在 Assembler 上以 10 为基数添加两个数字

Adding two numbers in base 10 on Assembler

如何将 2 个数字相加,它们的值以 16 为基数,并在汇编器上的 "base 10" 上生成结果。例如:

"5h+5h=10h" - I know it's wrong, I just want it to be visually 10h

而不是:

5h+5h=Ah

代码:

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.

我试图用 google 解决这个问题,但没有找到任何可以帮助我的东西...

这是您要查找的代码

MOV AX,5h
MOV BX,5h
ADD AX,BX
DAA

现在AX包含10h

好的,我在@Fifoernik 的帮助下弄明白了 所以问题是,如果我想用 16 位(例如 99h+1h)值来做,我需要像这样使用 DAA operan 和 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 仅在 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