How can I add 2 numbers that their value is on base 16 and make the result on "base 10" on assembler. 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...
Here is the code you are looking for
MOV AX,5h
MOV BX,5h
ADD AX,BX
DAA
Now AX contains 10h
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
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:
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.