程序集MASM将乘法结果添加到sum

时间:2014-01-28 09:38:39

标签: assembly x86 add masm multiplication

我找到一种方法将乘法结果添加到总和中有一点问题。假设我们只能使用寄存器(没有内存变量),我不确定我是如何能够实现这一点的。例如,如果我想计算这个表达式:

; 2013 * 365 + 765

mov ax, 365
mov bx, 2013
mul bx ; 2013 * 365
; The result would be DX:AX where EAX = 00003619 EDX = 0000000B 

mov cx, 765
; Now I am stuck here. I am not sure how can I add the result of multiplication
; to cx since it's DX:AX. Also, just to remind you, I am not allowed to use 
; any variables.
; Any help would be appreciated!

1 个答案:

答案 0 :(得分:1)

cx添加到dx:ax中的双字:

add ax,cx   ; ax += cx
adc dx,0    ; dx += the carry from the previous addition (0 or 1)