首页 文章

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

提问于
浏览
0

我在添加到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位寄存器中 . 谢谢您的帮助!

2 回答

  • 1

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

    (显然还有其他可能性 . )

  • 4
    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
    

    接下来回答您的 Headers 问题,并将结果DX:AX移动到32位寄存器,如EAX,您可以写:

    push dx
    push ax
    pop  eax
    

相关问题