使用教材
《汇编语言程序设计》
https://www.jianshu.com/p/8473cd0e92b6
查看系统上安装的 binutils 包
anno@anno-m:~$ dpkg -l | grep binutil
ii binutils 2.24-5ubuntu14.1 amd64 GNU assembler, linker and binary utilities
汇编语言 使用 AT&T 格式
test.s
#hello world!
.section .data
output:
.ascii "Hello world!\n"
len = . - output
.section .text
.globl _start
_start:
movl $4, %eax # 系统调用 _write
movl $1, %ebx # 文件描述符
movl $output, %ecx # 字符缓冲区
movl $len, %edx # 显示的字符数
int $0x80
movl $1, %eax
movl $0, %ebx
int $0x80 # 系统调用 _exit
汇编代码:编译、连接、运行
-
1、
as
:把汇编语言程序test.s
转换成目标文件test.o
; -
2、
ld
:从生成的目标文件test.o
创建可执行文件test
; -
3、运行可执行文件
test
,在屏幕上输出Hello world!;
anno@anno-m:~/Desktop$ as -o test.o test.s
anno@anno-m:~/Desktop$ ld -o test test.o
anno@anno-m:~/Desktop$ ./test
Hello world!
网友评论