64-assembly中的Imul [英] Imul in 64-assembly

查看:19
本文介绍了64-assembly中的Imul的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个代码:

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

imul 如何在 64 位汇编中工作?溢出的 aex 会写在 rax 的前 32 位吗?

How does imul work for 64-bit assembly? Will the overflow aex be written in the first 32 bits of rax?

推荐答案

你的代码 assembles

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

使用操作码 0F AF 作为 imul.该指令具有 32 位操作数大小,因此它只读取 EAX 和 EBX,并且只写入 EAX.这隐式零扩展到 RAX,将高 32 位清零.

which uses the opcode 0F AF for imul. This instruction has 32-bit operand size so it only read EAX and EBX, and only writes EAX. This implicitly zero-extends into RAX, zeroing the upper 32 bits.

imul 的 1 操作数形式不同,32x32 => 64 位全乘法的高半部分不会写入 EDX(或其他任何地方,如 RAX 的高半部分);它只是被丢弃或根本没有计算效率.请参阅文档;2 操作数 imul reg, r/m32 就像 add reg, r/m32or reg, r/m32 - 它没有不要做任何特别奇怪的事情.

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); 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.

在这个 32 位乘法完全没有意义之前使用 mov rax, imm64mov eax,0xfbc7a1ce 将给出完全相同的结果.(imul 不会破坏 RBX,所以你放入 RBX 的值的高 32 位仍然存在,如果你以后想读取它.它对 imul 指令,虽然.)

Using mov rax, imm64 before this 32-bit multiply is completely pointless, mov eax,0xfbc7a1ce would give exactly identical results. (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 eax, ebx, 0xfbc7a1ce 本来可以避免 mov.

Even better, imul eax, ebx, 0xfbc7a1ce could have avoided a mov.

这篇关于64-assembly中的Imul的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆