汇编语言编译环境搭建(MASM+NASM)
  0eGysyk4Lrwg 2023年11月02日 54 0

(目录)


一、Windows

1. 下载相关软件

  • DOSBox 官网:https://www.dosbox.com/ 或者 https://sourceforge.net/projects/dosbox/ 下载:DOSBox0.74-3-win32-installer.exe
  • MASM5.0 网上可以下载

2. 配置环境

image.png

双击之后,修改配置文件:

windowresolution=1024x768
output=ddraw

在DOSBox模拟器中挂载MASM5.0

mount c: d:\MASM5
c:
dir

配置自动挂载: 还是双击DOSBox0.74-3 Options.bat,在打开的配置文件中

[autoexec]
# Lines in this section will be run at startup.
# You can put your MOUNT lines here.
mount c: d:\MASM5
c:

3. 使用上的注意点

  • Alt + Enter 可以全屏并显示鼠标。
  • Ctrl + F10 显示鼠标
  • exit 退出

4. 编写测试代码并编译链接执行

  • 编写测试代码 hello.asm
.model small

.data
    strs DB 'hello world',13,10,'$'
.code
start:
    mov ax,@data
    mov ds,ax
    mov dx,offset strs
    mov ah,09h
    int 21h
    mov ah,4ch
    int 21h
end start
  • 编译 image.png

  • 链接 image.png

  • 执行 image.png

  • 调试

debug hello.exe
-r
-t
-q 退出

二、Linux(Ubuntu)

1. 安装nasm

$ sudo apt update
$ sudo apt install nasm

2. 准备hello world测试程序

hello.asm

;hello.asm
section .data
    msg db "hello, world!", 10

section .text
    global main

main:
    ;Write to stdout
    mov rax, 1
    mov rdi, 1
    mov rsi, msg
    mov rdx, 14
    syscall

    ;Exit
    mov rax, 60
    mov rdi, 0
    syscall

3. 编译程序

nasm -f elf64 hello.asm # 将生成hello.o
gcc hello.o
./a.out

编译为32位程序

gcc -m32 -nostartfiles hello.asm -o hello

将hello.asm源文件中的main改为_start。

nasm -f elf64 hello.asm # 将生成hello.o
ld -o hello hello.o
./hello

编译为32位程序

gcc -m32 hello.asm -o hello

其他32位编译指令

as --32 hello.asm -o hello.o
ld -melf_i386 -s -o hello hello.o

三、跨平台的汇编IDE SASM

SASM (SimpleASM) - simple Open Source crossplatform IDE for NASM, MASM, GAS, FASM assembly languages. SASM has syntax highlighting and debugger. The program works out of the box and is great for beginners to learn assembly language.

  • 官网:http://dman95.github.io/SASM/english.html
  • github:https://github.com/Dman95/SASM
【版权声明】本文内容来自摩杜云社区用户原创、第三方投稿、转载,内容版权归原作者所有。本网站的目的在于传递更多信息,不拥有版权,亦不承担相应法律责任。如果您发现本社区中有涉嫌抄袭的内容,欢迎发送邮件进行举报,并提供相关证据,一经查实,本社区将立刻删除涉嫌侵权内容,举报邮箱: cloudbbs@moduyun.com

  1. 分享:
最后一次编辑于 2023年11月08日 0

暂无评论

推荐阅读
  llt0tXqeaug8   2023年11月30日   31   0   0 g++ubuntuhive
  llt0tXqeaug8   2023年11月26日   41   0   0 ubunturubydocker
0eGysyk4Lrwg