INDEXED MEMORY MODE
.section .data
values:
.int 10,15,20,25,30,35,40,45,50,55,60
base_address(offset_address, index,size)
==> base_address + offset_address + index*size
movl $2, %edi
movl values(,%edi,4),%eax
间接寻址
- 在寄存器标号前加
$
取得是地址 - 在寄存器标号加
()
取的是该寄存器地址所指向的内存的内容
- example:
.section .data
values:
.int 10,15,20,25,30,35,40,45,50,55,60
.sectio .text
.globl main
main:
nop
movl values, %eax # %eax=10
movl $values, %edi # %edi=&values
movl $100, 4(%edi) # 15换成100
movl $1, %edi # %edi=1
movl values(,%edi,4),%ebx # 100赋给%ebx
movl $1 %eax # %eax = 1
int $0x80
-
inc
= ++ -
cmpl
比较 -
jne
jump if not equal
DATA EXCHANGE
XCHG operand1, operand2
-
bubble sort:
-
%esi
作为指针(保存数组起点) -
jge
jump greater then equal 后-前是否>=0 -
dec
=--
-
jnz
上一条语句的结果是否为0 -
xchg
寄存器和操作数
ADD
add? sourcr destination
把source加到destinationSource operand: register,memory,immediate value
-
Destination operand:register,memory
CF: 若进位则为1
OF: 前面两个高位相同且与第三个高位不同则为1
SF: 结果的高位是什么就是什么
ZF: 结果是0就是1 否则为0
sub? source destination
:destination - sourceneg? destination
:取反(negative)inc? destination
:--
dec? destination
:++
-
mul? source
:无符号数乘法-
8位的数与
%al
相乘,结果放入%ax
中 imul? source
imul? source, destination
-
imul? multipler, source, destination
:destination = multipler*source
-
8位的数与
DIVIDE
- dividend / devisor = quotient * divisor + remainder
div? divisor
idiv? divisor
- 被除数是除数长度的两倍
SHIFT LEFT(MULTIPLY 2^N)
-
sal? destination
: *2 -
sal? %cl,destination
: *2^cl -
sal? shifter destination
: *2^shifter(立即数) shl? (as same as sal)
SHIFT RIGHT(DIVIDED BY 2^N)
sar? destination
-
sar? %cl,destination
: /2^cl -
sar? shifter destination
: /2^shifter(立即数) shr? (same as sar except always filling zero)
ROTATE SHIFT
BOOLEAN LOGIC
- NOT
not? destination
- AND
- OR
- XOR
-
and?/or?/xor? source, destination
-
- 清零
- xor 三个时钟周期
- mov 四个时钟周期
REVIEW
INSTRUCTION POINTER
-
jmp
无条件跳