Moving from DX:AX register to single 32 bit register

前端 未结 2 1118
不思量自难忘°
不思量自难忘° 2021-01-26 05:13

I\'m having a problem adding to a product of a 16 bit multiplication. I want to multiply a year such as 2015, by 365 to do so I

mov dx, 0    ; to clear the regis         


        
2条回答
  •  死守一世寂寞
    2021-01-26 05:21

    The usual method is to use a 32 bit multiply to start with. It's especially easy if your factor is a constant:

    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
    

    You can of course also combine 16 bit registers, but that's not recommended. Here it is anyway:

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

    (There are other possibilities too, obviously.)

提交回复
热议问题