2015-10-16 201 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 
相關問題