-4
我想在程序集中添加兩個30位數字。正如你在8086所知道的那樣,我們不能在30位數字中添加兩個數字。所以我必須用字符串來完成。並使用AAA命令並將結果放在sum變量中,最後檢查我們是否執行或不執行,但主要問題是總和的結果是不正確的。這是給我59427532總和這668399 + 759133.爲什麼我沒有得到正確的結果
你能告訴我哪裏是確切的問題?
.model small
.stack 64
.data
max1 db 30
acc1 db ?
num1 db 30 dup('0')
max2 db 30
acc2 db ?
num2 db 30
sum db 31 dup('0'),'$'
.code
start:
mov ax,@data
mov ds, Ax
mov ah,0ah
lea dx, max1 ;take max 1 and length store it to acc1
int 21h
mov ah,0ah
lea dx,max2 ;take max2 and length store it to acc2
int 21h
mov cl,acc1 ;check if they are equal
cmp cl,acc2
jne exit
mov ch,0 ;make sure our cx is the length of our string
clc
mov si,cx ;set the length for index the char
dec si
l1:
mov al,num1[si] ;sum two hex number
adc al,num2[si] ;add with carry flag
aaa ;seperate carry and hex number and store it into al
pushf
add al,30h ;convert it to ascii again
mov sum[si+2],al ;because of dec si we have to step
popf
dec si
loop l1
jne print
mov sum,31h ; if we have carry flag add to sum otherwise jumpt print
print:
mov ah,09h ;the main problem is here shows the result
lea dx,sum
int 21h
exit:
mov ax,4c00h
int 21h
end start
當你的問題被充分地回答,你應該接受現場給出最好的答案,即使這是你自己的! (這會給你一個徽章) – SamStar 2012-04-19 14:43:50