FASM HelloWorld.exe 程序

发布于 2024-10-02 11:28:27 字数 514 浏览 8 评论 0原文

我尝试在 FASM 上编写我的第一个 .exe 程序。当我使用 org 100h 时它工作正常,但我想编译 .exe 文件。当我用“format PE GUI 4.0”替换第一行并尝试编译它时,出现错误:“值超出范围”(行:mov dx,msg)。

ORG 100h      ;format PE GUI 4.0

mov dx,msg
mov ah,9h
int 21h

mov ah,10h
int 16h

int 21h

msg db "Hello World!$" 

我应该如何更改源代码?
--------------------------------------------------------< br> 答案是:

format mz
org 100h

mov edx,msg
mov ah,9h
int 21h

mov ah,10h
int 16h

mov ax,$4c01
int 21h

msg db "Hello World!$" 

I tried to write my first .exe program on FASM. It works ok when I use org 100h, but I want to compile .exe file. When I replaced first line with "format PE GUI 4.0" and tried to compile it the error occured: "value out of range" (line: mov dx,msg).

ORG 100h      ;format PE GUI 4.0

mov dx,msg
mov ah,9h
int 21h

mov ah,10h
int 16h

int 21h

msg db "Hello World!$" 

How should I change the source code?

----------------------------------------------
The answer is:

format mz
org 100h

mov edx,msg
mov ah,9h
int 21h

mov ah,10h
int 16h

mov ax,$4c01
int 21h

msg db "Hello World!$" 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

杀お生予夺 2024-10-09 11:28:27

您的第一个版本是 COM 格式。它是一个 16 位实模式 FLAT 模型。
您的第二个版本是 DOS MZ 格式。它是一个 16 位实模式 SEGMENTED 模型。

分段模型使用“段”来描述您的 DS(段)和 DX(偏移)。因此,首先您需要为数据和代码定义段,其次您需要正确指出数据段在哪里以及偏移量是多少,然后才能使用 int 21h,函数 9。

int 21h,函数 9 需要DS:DX 在分段模型中正确设置,以打印空终止字符串

format MZ
entry .code:start
segment .code
start:
mov ax, .data ; put data segment into ax
mov ds, ax    ; there, I setup the DS for you
mov dx, msg   ; now I give you the offset in DX. DS:DX now completed.
mov ah, 9h
int 21h
mov ah, 4ch
int 21h
segment .data
msg db 'Hello World', '

希望这可以帮助一些 FASM 新手。

希望这可以帮助一些 FASM 新手。

Your first version is in COM format. It is a 16-bit real mode FLAT model.
Your second version is in DOS MZ format. It is a 16-bit real mode SEGMENTED model.

Segmented model uses "segments" to describe your DS (segment) and DX (offset). So firstly you need to define segments for your data and code, and secondly you need to point correctly where is your data segment and what is your offset before you can use the int 21h, function 9.

int 21h, function 9 needs a DS:DX to be setup correctly in segmented model, to print a null terminated string

format MZ
entry .code:start
segment .code
start:
mov ax, .data ; put data segment into ax
mov ds, ax    ; there, I setup the DS for you
mov dx, msg   ; now I give you the offset in DX. DS:DX now completed.
mov ah, 9h
int 21h
mov ah, 4ch
int 21h
segment .data
msg db 'Hello World', '

Hope this helps some FASM newbies out there.

Hope this helps some FASM newbies out there.

谁人与我共长歌 2024-10-09 11:28:27

如果您想要 DOS exe,则需要格式 mz

If you want DOS exe, you need format mz.

人│生佛魔见 2024-10-09 11:28:27

您可能想尝试使用lea(即lea dx, msg);这需要操作数的偏移量,并且可能更适合您想要的......

You might want to try using lea instead (i.e., lea dx, msg); this takes the offset of the operand, and may be better suited to what you're wanting...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文