.
386
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
.data
szCaption db ' A MessageBox ' , 0
szText db ' Hello! ' , 0
.code
start:
invoke MessageBox,NULL,offset szText,offset szCaption,MB_OK
invoke ExitProcess,NULL
end start
.model flat,stdcall
option casemap:none
include windows.inc
include user32.inc
includelib user32.lib
include kernel32.inc
includelib kernel32.lib
.data
szCaption db ' A MessageBox ' , 0
szText db ' Hello! ' , 0
.code
start:
invoke MessageBox,NULL,offset szText,offset szCaption,MB_OK
invoke ExitProcess,NULL
end start
程序其实挺简单,看看也都对,书上也提示对于汇编来说必须先ml生成obj文件再link成exe文件。
在命令窗口满怀信心地键入ml first.asm,居然出错~提示说window.inc找不到,肯定是环境变量没有设置好。 但是翻遍目录没找到配置环境变量的程序(脱离了IDE真有点无所适从)。于是,又写个批处理文件,设定一些目录与环境,批处理如下:
@echo off
set include = d:\masm32\bin\include
set lib = d:\masm32\lib
set path = d:\masm32\bin; % path %
echo on
set include = d:\masm32\bin\include
set lib = d:\masm32\lib
set path = d:\masm32\bin; % path %
echo on
执行后,可以在命令窗口下任何目录中调用bin中的命令,而不会出现Bad Command命令,不过,上面的老问题还是没有解决。最后,只好把程序include后面的文件加上全部路径,问题解决!包含代码如下:
include d:\masm32\include\windows.inc
include d:\masm32\include\user32.inc
includelib d:\masm32\lib\user32.lib
include d:\masm32\include\kernel32.inc
includelib d:\masm32\lib\kernel32.lib
include d:\masm32\include\user32.inc
includelib d:\masm32\lib\user32.lib
include d:\masm32\include\kernel32.inc
includelib d:\masm32\lib\kernel32.lib
这个问题一直想不明白,不过,倒了解了有关批处理文件的知识。
正确生成obj文件后,下一次就是进行链接了,以生成exe文件,直接敲入命令link first.obj,居然又通不过,这次的错误提示更是摸不着头脑。提示:a subsystem can't be inferred and must be defined,仔细翻了一下书,原来命令还有个参数:
link /subsystem:windows first.obj --->这样就可以通过链接 真是....Faint~~~~