如何添加2个数字,它们的值在基数16上,并在汇编程序的“基数10”上生成结果。例如:
"5h+5h=10h" - I know it's wrong, I just want it to be visually 10h
而不是:
5h+5h=Ah
CODE:
MOV AX,5h
MOV BX,5h
ADD AX,BX
result: ax=Ah - Not the result that i want...
result: ax=10h - The result that i want.
我试图用谷歌解决这个问题,但没找到任何可以帮助我的东西......
答案 0 :(得分:4)
以下是您要查找的代码
MOV AX,5h
MOV BX,5h
ADD AX,BX
DAA
现在AX包含10h
答案 1 :(得分:1)
好的,所以我在@Fifoernik的帮助下弄清楚了
所以问题是,如果我想用16位(例如99h+1h
)值来做,我需要使用DAA
operan和CF
标志
pop ax
pop bx
add al,bl
daa ; dec id values
mov cl,al
mov al,ah
jc Carry; do i have carry
add al,bh
daa ; do the magic thing
JMP finito
Carry:
add al,1 ; add the carring...
add al,bh
daa ;can some one tell me what exactly daa does?
finito:
mov ch,al
push cx
ret
daa仅在AL
上工作,所以你需要使用进位标志来添加进位,如:
AH AL
1 <----- carry
00 99 <-- DAA take care of the 99 and make it 0 when its A0h
00 01+
-- --
01 00 ---> result 100h