[英]Moving from DX:AX register to single 32-bit register
I'm having a problem adding to a product of a 16-bit multiplication.我在添加到 16 位乘法的乘积时遇到问题。 I want to multiply a year (such as 2015) by 365. To do so I
我想将一年(例如 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
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.
我想向产品添加单独的值,因此我想将此产品移动到单个 32 位寄存器中。
The usual method is to use a 32 bit multiply to start with.通常的方法是使用 32 位乘法开始。 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.您当然也可以组合 16 位寄存器,但不推荐这样做。 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.) (显然,还有其他可能性。)
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:接下来回答您的标题问题并将结果 DX:AX 移动到像 EAX 这样的 32 位寄存器中,您可以编写:
push dx
push ax
pop eax
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.