简体   繁体   English

64-assembly中的Imul

[英]Imul in 64-assembly

I have this code:我有这个代码:

mov rax, 0x93f3ffc2fbc7a1ce
mov rbx, 0x5862d8a05a385cbe
imul eax, ebx

How does imul work for 64-bit assembly? imul 如何用于 64 位程序集? Will the overflow aex be written in the first 32 bits of rax?溢出 aex 会写在 rax 的前 32 位吗?

Your code assembles to你的代码组装

0:  48 b8 ce a1 c7 fb c2    movabs rax,0x93f3ffc2fbc7a1ce
7:  ff f3 93
a:  48 bb be 5c 38 5a a0    movabs rbx,0x5862d8a05a385cbe
11: d8 62 58
14: 0f af c3                imul   eax,ebx

which uses the opcode 0F AF for imul .它对imul使用操作码0F AF This instruction has 32-bit operand size so it only read EAX and EBX, and only writes EAX.该指令具有 32 位操作数大小,因此它只读取 EAX 和 EBX,并且只写入 EAX。 This implicitly zero-extends into RAX , zeroing the upper 32 bits.隐式地零扩展到 RAX ,将高 32 位清零。

Unlike the 1-operand form of imul , the high-half of the 32x32 => 64-bit full multiply isn't written to EDX (or anywhere else like the high half of RAX);imul的 1 操作数形式imul ,32x32 => 64 位全乘法的高半部分不会写入 EDX(或其他任何地方,如 RAX 的高半部分); it's simply discarded or for efficiency not even calculated at all.它只是被丢弃或根本没有计算效率。 See the documentation ;请参阅文档 2-operand imul reg, r/m32 is just like add reg, r/m32 or or reg, r/m32 - it doesn't do any special weird stuff. 2-operand imul reg, r/m32就像add reg, r/m32or reg, r/m32 - 它没有做任何特别奇怪的事情。

Using mov rax, imm64 before this 32-bit multiply is completely pointless, mov eax,0xfbc7a1ce would give exactly identical results.在这个 32 位乘法完全没有意义之前使用mov rax, imm64mov eax,0xfbc7a1ce会给出完全相同的结果。 (The imul doesn't destroy RBX, so the upper 32 bits of the value you put into RBX is still there if you want to read it later. It has no effect on the imul instruction, though.) imul不会破坏 RBX,因此如果您想稍后读取它,那么您放入 RBX 的值的高 32 位仍然存在。不过, imul指令没有影响。)

Even better, imul eax, ebx, 0xfbc7a1ce could have avoided a mov .更好的是, imul eax, ebx, 0xfbc7a1ce可以避免mov

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM