x86-32汇编语言基础汇总
常用命令
从C代码生成汇编代码
gcc -O2 -S code.c -m32 -fno-omit-frame-pointer
编译.s文件为.o文件
as -o code.o code.s --32
使用gdb调试则加
-gstabs
链接.o文件生成可执行文件
ld -o exe code1.o code2.o -m elf_i386
调用lib_c库函数
ld命令加上参数,-m参数也不能丢
-lc -dynamic-linker /lib/ld-linux.so.2
output:
.asciz "The number is %d\n"
num:
.long 666
.section .text
.globl _start
_start:
movl $num, %eax
pushl (%eax)
push $output
call printf
addl $8, %esp
push $0
call exit
保存为test.s,然后使用命令
as test.s -o test.o --32
ld test.o -o test -m elf_i386 -lc -dynamic-linker /lib/ld-linux.so.2
./test
即可观察到输出。
基础语法
1.数据
C声明 | Intel数据类型 | 汇编代码后缀 | 大小(字节) |
---|---|---|---|
char | 字节 | b | 1 |
short | 字 | w | 2 |
int | 双字 | l | 4 |
long int | 双字 | l | 4 |
char* | 双字 | l | 4 |
float | 单精度 | s | 4 |
double | 双精度 | l | 8 |
long double | 扩展精度 | t | 10/12 |
汇编语言指令所处理的数据类型一般是采用汇编语言的后缀来进行区分。