繁体   English   中英

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

[英]Moving from DX:AX register to single 32-bit register

我在添加到 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

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

通常的方法是使用 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

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

shl edx, 16 ; move top 16 bits into place
mov dx, ax  ; move bottom 16 bits into place

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

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

您可以从简化此代码开始(在进行乘法运算之前您不需要清除任何寄存器):

mov  ax, 365
mul  cx       ; result in dx:ax

接下来回答您的标题问题并将结果 DX:AX 移动到像 EAX 这样的 32 位寄存器中,您可以编写:

push dx
push ax
pop  eax

暂无
暂无

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

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