Moving from DX:AX register to single 32 bit register

南笙酒味 提交于 2019-12-31 06:04:07

问题


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

After checking the registers, I am getting the correct solution but is there a way so that I can store this product into a single register. I want to add separate values to the product and so I would like to move this product into a single 32 bit register. Thanks for the help!


回答1:


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.)




回答2:


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

You can start by simplifying this code (You don't need to clear any register before doing the multiplication):

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

Next to answer your title question and have the result DX:AX moved into a 32-bit register like EAX you could write:

push dx
push ax
pop  eax


来源:https://stackoverflow.com/questions/33181034/moving-from-dxax-register-to-single-32-bit-register

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!