masm32基本配置与写出第一个汇编程序

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)

五、程序执行效果

猜你喜欢

转载自www.cnblogs.com/onetrainee/p/12093802.html