FASM HelloWorld.exe 程序
我尝试在 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您的第一个版本是 COM 格式。它是一个 16 位实模式 FLAT 模型。
您的第二个版本是 DOS MZ 格式。它是一个 16 位实模式 SEGMENTED 模型。
分段模型使用“段”来描述您的 DS(段)和 DX(偏移)。因此,首先您需要为数据和代码定义段,其次您需要正确指出数据段在哪里以及偏移量是多少,然后才能使用 int 21h,函数 9。
int 21h,函数 9 需要DS:DX 在分段模型中正确设置,以打印空终止字符串
希望这可以帮助一些 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
Hope this helps some FASM newbies out there.
如果您想要 DOS exe,则需要格式 mz。
If you want DOS exe, you need format mz.
您可能想尝试使用
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...