2015-10-16 134 views
0

我在添加到16位乘法乘积时遇到问题。我想比如一年繁殖截至2015年,由365这样做,我从DX:AX寄存器移动到单个32位寄存器

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位寄存器中。 感谢您的帮助!

回答

3

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

(还有其他的可能性也明显)

1
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搬进了32位寄存器,如:EAX你可以写:

push dx 
push ax 
pop eax 
相关问题