(目录)
一、Windows
1. 下载相关软件
- DOSBox 官网:https://www.dosbox.com/ 或者 https://sourceforge.net/projects/dosbox/ 下载:DOSBox0.74-3-win32-installer.exe
- MASM5.0 网上可以下载
2. 配置环境
双击之后,修改配置文件:
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
-
编译
-
链接
-
执行
-
调试
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