80386 模拟器源码分析 (3)
NASM
参考 NASM tutorial,新建一个 hello.asm
文件
section .text
global _start ;must be declared for linker (ld)
_start: ;tells linker entry point
mov edx,len ;message length
mov ecx,msg ;message to write
mov ebx,1 ;file descriptor (stdout)
mov eax,4 ;system call number (sys_write)
int 0x80 ;call kernel
mov eax,1 ;system call number (sys_exit)
int 0x80 ;call kernel
section .data
msg db 'Hello, world!', 0xa ;string to be printed
len equ $ - msg ;length of the string
# 进入 docker i386
$ docker exec -it xxx bash
# 安装 nasm 和 llvm
$ apt-get install nasm
$ apt-get install llvm
# 编译 & 测试
$ nasm -f elf hello.asm
$ ld -m elf_i386 -s -o hello hello.o
$ ./hello
Hello, world!
调试
https://stackoverflow.com/questions/13506629/lldb-break-at-address
$ nm ./hello
nm: ./hello: no symbols
$