从 DX:AX 寄存器移动到单个 32 位寄存器

San*_*lip 0 x86 assembly masm

我在添加到 16 位乘法的乘积时遇到问题。我想将一年(例如 2015 年)乘以 365。为此,我

mov dx, 0    ; to clear the register
mov ax, cx   ; cx holds the year such as 2015
mov dx, 365  ; to use as multiplier
mul dx       ; multiply dx by ax into dx:ax
Run Code Online (Sandbox Code Playgroud)

检查寄存器后,我得到了正确的解决方案,但有没有办法可以将这个产品存储到单个寄存器中?我想向产品添加单独的值,因此我想将此产品移动到单个 32 位寄存器中。

Jes*_*ter 5

通常的方法是使用 32 位乘法开始。如果您的因子是常数,则特别容易:

movzx ecx, cx      ; zero extend to 32 bits
                   ; you can omit if it's already 32 bits
                   ; use movsx for signed
imul ecx, ecx, 365 ; 32 bit multiply, ecx = ecx * 365
Run Code Online (Sandbox Code Playgroud)

您当然也可以组合 16 位寄存器,但不推荐这样做。无论如何,这里是:

shl edx, 16 ; move top 16 bits into place
mov dx, ax  ; move bottom 16 bits into place
Run Code Online (Sandbox Code Playgroud)

(显然,还有其他可能性。)