FASM HelloWorld .exe程序 [英] FASM HelloWorld .exe program

查看:209
本文介绍了FASM HelloWorld .exe程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图在FASM上编写我的第一个.exe程序.当我使用org 100h时,它可以正常工作,但是我想编译.exe文件.当我用"format PE GUI 4.0格式"替换第一行并尝试对其进行编译时,发生了错误:值超出范围"(行:mov dx,msg).

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

推荐答案

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

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.

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

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,功能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新手.

Hope this helps some FASM newbies out there.

这篇关于FASM HelloWorld .exe程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆