1

我尝试在 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!$" 

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

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!$" 
4

3 回答 3

4

您的第一个版本是 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 新手。

于 2011-02-23T16:57:12.753 回答
2

如果你想要 DOS exe,你需要格式 mz

于 2010-11-14T05:01:17.233 回答
-1

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

于 2010-11-13T21:30:37.927 回答