配置教程参考了piratf的64位Windows环境下通过"Sublime Text 3"搭建汇编语言IDE,实际配置环境为Windows 7 32位。
- 安装
Sublime Text 3和Package Control,使用Package Control安装MasmAssembly
这一步若有问题请参见这里。 - 安装
masm32
masm32是我们编译汇编语言的工具。 - 下载
DosBox
DosBox的作用是运行16位程序。
在Windows变量中分别添加include、lib、path三个变量,我的配置如下:

请根据你的masm32路径进行修改。
下载asm.bat,并存储到masm32的bin文件夹下。
在Sublime Text 3中,选择Tools->Build System -> New Build System…,将以下内容粘贴进去(覆盖原内容):
{
"cmd": ["c:\\masm32\\bin\\asm.bat", "$file_base_name"],
"file_regex": "^[ ]*File \"(...*?)\", line ([0-9]*)",
"selector": "source.asm",
"encoding":"cp936",
"variants":
[
{
"name": "Run",
"cmd": ["start","CMD", "/U", "/C","debug $file_base_name.exe"],
"shell":true
}
]
}保存文件名为Asm16。
在Sublime Text 3中,选择Tools->Build System -> New Build System…,将以下内容粘贴进去(覆盖原内容):
{
"cmd":["ml","/coff","/Cp","/Ic:/masm32/include","$file_name","/link","/subsystem:windows",
"/libpath:c:/masm32/lib"],
"selector":"source.asm"
}保存文件名为Asm32。
然后,将这里提供的link.exe替换掉masm32的bin中的同名文件。
由于16位程序只能在DosBox的虚拟环境中运行,因此我们要对DosBox进行一些设置。
首先,新建一个文件夹,如我在C盘下新建了一个DEBUG文件夹(当然,你也可以根据自己的需要在任意盘符下新建一个文件夹,文件夹名随意),里面存放你的16位汇编程序以及一些DosBox工具,我的DEBUG下有这些工具。
双击打开DosBox文件夹下的DOSBox 0.74 Options,在末尾加入:
mount C C:\DEBUG
C:
其中,C:\DEBUG改为你自己新建的文件夹的路径。
到这里,我们的配置工作就基本完成了。现在,我们尝试来对16位汇编程序以及32位汇编程序进行编译与运行。
首先,在Sublime Text 3中新建空白文件,写入以下内容:
data segment abc db "hello, world!", 0Dh, 0Ah, "$" data ends code segment assume cs:code, ds:data main: mov ax, data mov ds, ax mov ah, 9 mov dx, offset abc int 21h mov ah, 4Ch int 21h code ends end main
保存为hello.asm到C:\DEBUG中(或你自己新建的文件夹的路径中)。然后在Sublime Text 3中,选择Tools -> Build System -> Asm16,再使用快捷键ctrl+shift+B,上下键选择Asm16回车,即可完成编译。
然后打开Dosbox,直接输入hello即可运行16位程序。
在Sublime Text 3中新建空白文件,写入以下内容:
.386 .model flat, stdcall option casemap :none include include\windows.inc include include\kernel32.inc include include\user32.inc includelib lib\kernel32.lib includelib lib\user32.lib .data result db 100 dup(0); dup:duplicate重复 ;char result[100]={0}; format db "%d",0; db:define byte字节类型 ; char format[3]="%d"; prompt db "The result",0 above db "Above or equal", 0 below db "Below", 0 .code main: ; 标号 mov eax, 0; eax:extended ax mov ebx, 1 again: add eax, ebx; eax=0+1+2+3 add ebx, 1 ; ebx=4 cmp ebx, 100; cmp:compare jbe again ; jbe:jump if below or equal mov ebx, eax cmp eax, 5000 jae above_or_equal invoke MessageBox, 0, offset below, offset prompt,0 jmp done above_or_equal: invoke MessageBox, 0, offset above, offset prompt, 0 done: mov eax, ebx invoke wsprintf, offset result, offset format, eax invoke MessageBox,0,offset result,offset prompt,0 ret end main; 指定程序的起始执行点
保存为sum.asm到C:\DEBUG中(或你自己新建的文件夹的路径中)。然后在Sublime Text 3中,选择Tools -> Build System -> Asm32,再使用快捷键ctrl+B,即可完成编译。如果编译报错找不到include文件夹,请将masm32中include和lib两个文件夹复制到C:\DEBUG中,再次ctrl+B编译即可。生成的32位程序不能在DosBox中运行,直接双击打开即可。