In-depth understanding of computer systems - Chapter III -3.5 arithmetic and logic operations

Disclaimer: This article is a blogger original article, follow the CC 4.0 BY-SA copyright agreement, reproduced, please attach the original source link and this statement.
This link: https://blog.csdn.net/weixin_40199047/article/details/102519548

3.5 arithmetic and logic operations

Write pictures described here

3.5.1 load effective address

Load effective address ( load effective address) instruction leaqis actually a movqmodification 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 .
Write pictures described here

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:Write pictures described here

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 to movl $0, %edx(5 bytes)

3.5.5 special arithmetic operations

Write pictures described here
imulqThere are two different forms of instruction. One is a "double operand" multiply instruction. It is from two 64to generate a bit operand 64bit products, realized 2.3.4and 2.3.5operating section 64 in *_{64}^u 64 in *_{64}^u (将乘积截取到64位时,无符号乘法和补码乘法的位级行为是一样的。)。
另一种“单操作数”乘法指令(包含无符号乘法(mulq)和补码乘法(imulq)。
这两条指令都要求一个参数必须在寄存器 %rax 中,而另一个作为指令的源操作数给出。乘积存放在寄存器 %rdx(高64位)和 %rax(低64位)中。
示例:
Write pictures described here
除法和取模操作。有符号除法指令 idivl 将寄存器 %rdx(高64位)和%rax(低64位)中的 128 位数作为除数,而除数作为指令的操作数给猪。指令将商存储在寄存器 %rax 中,将余数存储在寄存器 %rdx 中(取模运算结果)。
特殊点:对于64 位除数来说,这个值通常存放在 %rax 中, %rdx 的位一个设置全为 0 (无符号运算)或者 %rax 的符号位(有符号运算)(可以用一个无操作数指令 cqto 来完成,该指令隐含读出 %rax 的符号位并将结果复制到 %rdx 的所有位)。
示例:
Write pictures described here
Write pictures described here

qpThe need to save another register, the division operation takes %rdx, , cqto R[%rdx]:R[%rax] <-- 符号拓展 R[%rax]the supplier %raxand the remainder in %rdxthe.
Unsigned division used divq, typically %rdxprior to zero.

Guess you like

Origin blog.csdn.net/weixin_40199047/article/details/102519548