[英]Adding two numbers in base 10 on Assembler
How can I add 2 numbers that their value is on base 16 and make the result on "base 10" on assembler. 我该如何将2个数字加起来,使它们的值以16为底,并在汇编器上以“ 10为底”进行计算。 For example: 例如:
"5h+5h=10h" - I know it's wrong, I just want it to be visually 10h
And not: 并不是:
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.
I tried to figure it out with google but didn't find anything that can help me... 我试图用Google弄清楚,但没有找到任何可以帮助我的东西...
Here is the code you are looking for 这是您要查找的代码
MOV AX,5h
MOV BX,5h
ADD AX,BX
DAA
Now AX contains 10h 现在AX包含10小时
Ok so i figure it out with @Fifoernik 's help so the problem is that if i want to do it with 16bit (for example 99h+1h
) values i need to do it like this using DAA
operan and CF
flag 好的,所以我可以通过@Fifoernik的帮助来解决问题,所以问题是,如果我想使用16位(例如99h+1h
)值来执行此操作,则需要使用DAA
数和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 working only on AL
so you'ill need to use the carry flag to add the carry like: 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
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.