3.5 arithmetic and logic operations
3.5.1 load effective address
Load effective address ( load effective address
) instruction leaq
is actually a movq
modification instruction. It is the form of instructions from memory to the read data register, but in fact it does not have a reference memory, but the effective address is written to the destination operand .
Unary and binary operations 3.5.2
e.g
:
Unary operators:
incq (%rsp)
Binary:
subq %rax, %rdx
3.5.3 shift operation
Left shift command has two names: SAL and SHL (both the same effect, are up on the right side of 0). Right shift instruction has two: SAR arithmetic right shift (sign bit fill the left), and performs a logical shift SHR (0 fill).
3.5.4 discussion
Most instructions may be used to unsigned operation, it may be used to complement arithmetic. Right shift operation requires only distinguishing unsigned and signed.
Example:
tips:
xorq %rdx, %rdx
To seek 0% rdx
Any updates will lower 4 bytes of instruction 0 is set to the high byte
xorl %edx, %edx
(Byte)
is equivalent tomovl $0, %edx
(5 bytes)
3.5.5 special arithmetic operations
imulq
There are two different forms of instruction. One is a "double operand" multiply instruction. It is from two 64
to generate a bit operand 64
bit products, realized 2.3.4
and 2.3.5
operating section
和
(将乘积截取到64
位时,无符号乘法和补码乘法的位级行为是一样的。)。
另一种“单操作数”乘法指令(包含无符号乘法(mulq
)和补码乘法(imulq
)。
这两条指令都要求一个参数必须在寄存器 %rax
中,而另一个作为指令的源操作数给出。乘积存放在寄存器 %rdx
(高64
位)和 %rax
(低64
位)中。
示例:
除法和取模操作。有符号除法指令 idivl
将寄存器 %rdx
(高64
位)和%rax
(低64
位)中的 128
位数作为除数,而除数作为指令的操作数给猪。指令将商存储在寄存器 %rax
中,将余数存储在寄存器 %rdx
中(取模运算结果)。
特殊点:对于64
位除数来说,这个值通常存放在 %rax
中, %rdx
的位一个设置全为 0
(无符号运算)或者 %rax
的符号位(有符号运算)(可以用一个无操作数指令 cqto
来完成,该指令隐含读出 %rax
的符号位并将结果复制到 %rdx
的所有位)。
示例:
qp
The need to save another register, the division operation takes %rdx
, , cqto R[%rdx]:R[%rax] <-- 符号拓展 R[%rax]
the supplier %rax
and the remainder in %rdx
the.
Unsigned division used divq
, typically %rdx
prior to zero.