AT&T 汇编入门 - 寻址方式
网上已经有很多文章讲述寻址方式。
其实从汇编的角度来看,寻址方式分为以下4种基本类型化。
- 立即数寻址
- 寄存器寻址
- 内存寻址
- IO 端口寻址
立即数寻址
movl $0x1234, %rdi
addl 22, value
寄存器寻址
movl %rax, %rbx
movl %rax, space
内存寻址
section : displacement(base, index, scale)
- base: 64位的寄存器
- Index:64位的寄存器
- scale: 2 / 4 / 8 / …
- displacement:可以是一个 8位,16位,或者32位的值。
effective address = disp + base + index * scale
注意,如果没有制定段,默认是DS,也就是data 段,但是有时候寄存器会隐形的指定段,假设你传入的base 是 rsp 寄存器,那么对应的就是 SS 段中的数据。
movq 4(%rbx), %rcx
movq -4(%rbx), %rcx
movq values(, %rdi, 4), %rax
movq (%rsi, %rdi, 4), %rax
相对寻址 (只有64位支持)
lea values(%rip), %rdi