masm32基本配置與寫出第一個匯編程序
在windows系統上,如果編寫C/C++等程序,只需利用visual Studio即可,但如果打算編寫匯編程序,往往需要另外配置很多東西,另新手望而卻步。
masm32是由個人開發的一套可以在Windows平台上編寫匯編的工具,只需要簡單配置,就可以編寫匯編程序。
注意:不要與微軟的masm宏編譯器搞混,兩者不是一個概念。
一、masm32的安裝
去官網,然后DownLoad,一路下來,安裝到C盤或D盤根目錄下即可。
二、配置環境變量(用戶變量)
分別配置 include(xx.inc的頭文件);lib(靜態鏈接庫);PATH(工具的路徑)。
注意:如果你不添加環境變量,之后你在匯編文件中寫代碼,其包含文件必須使用絕對路徑(include \xxx\xxx\masm32.inc)

三、寫一個匯編代碼
1 .386 2 .model flat, stdcall 3 option casemap:none 4 5 include kernel32.inc 6 includelib kernel32.lib 7 8 include masm32.inc 9 includelib masm32.lib 10 11 .data 12 msg1 db "What is your name? ", 0 13 msg2 db "Hello ",0 14 15 .data? 16 buffer db 100 dup(?) ; reserve 100 bytes for input storage 17 18 .code 19 start: 20 push offset msg1 ; put in to stack the effective add of msg1 21 call StdOut ; call console display API 22 23 push 100 ; set the maximum input character 24 push offset buffer ; put in to stack the effective add of input storage 25 call StdIn ; call console input API 26 27 push offset msg2 ; put in to stack the effective add of msg2 28 call StdOut ; call console display API 29 30 push offset buffer ; put in to stack the effective add of input storage 31 call StdOut ; call console display API 32 33 exit: 34 push 0 35 call ExitProcess 36 end start
四、編譯並執行
1. 定位到 a.asm 文件中。
2. 匯編,生成 a.obj 文件 ml /c /coff a.asm
3. 鏈接,生成 a.exe 文件 link /subsystem:console a.obj (注意:這是命令行程序,如果生成窗口程序,subsystem的參數要修改為 windows)
五、程序執行效果

