- 代码:
#hello.s
.data
msg : .string "hello world\n"
len = . - msg
.text
.global _start
_start:
movl $len, %edx
movl $msg, %ecx
movl $1, %ebx
movl $4, %eax
int 0x80
movl $0, %ebx
movl $1, %eax
int 0x80
- 汇编gcc hello.s -c -o hello.o
- 链接ld hello.o -o hello(gcc hello.o -o hello会报"_start被多次定义",“对main未定义的引用”)
- int $0x80是AT&T语法中的一条中断指令,用于Linux的系统调用
- Linux write系统调用的原型:
ssize_t write(int fd, const void *buf, size_t count);
fd, 文件描述符,1表示标准输出,即输出到控制台
buf, 缓冲区指针
count, 写到文件fd的字节数
- syscall x86上的Linux 接口声明您将syscall数字加载到其中eax,并放置其他参数ebx,ecx依此类推