簡體   English   中英

在匯編器的基數10中添加兩個數字

[英]Adding two numbers in base 10 on Assembler

我該如何將2個數字加起來,使它們的值以16為底,並在匯編器上以“ 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包含10小時

好的,所以我可以通過@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僅在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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM