从DX:AX寄存器移至单个32位寄存器 [英] Moving from DX:AX register to single 32-bit register

查看:97
本文介绍了从DX:AX寄存器移至单个32位寄存器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

将16位乘法的乘积相加时遇到问题.我想将一年(例如2015年)乘以365.为此,我

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

检查寄存器后,我得到了正确的解决方案,但是有什么方法可以将产品存储到单个寄存器中?我想为产品添加单独的值,因此我想将此产品移至单个32位寄存器中.

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

您当然也可以合并16位寄存器,但是不建议这样做.反正就是这样:

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

这篇关于从DX:AX寄存器移至单个32位寄存器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆