【问题标题】:Why I don't get the right result为什么我没有得到正确的结果
【发布时间】:2012-04-15 16:38:34
【问题描述】:

我想用汇编添加两个 30 位数字。如您所知,在 8086 中我们不能添加两个 30 位数字。所以我必须用字符串来做。并使用 AAA 命令将结果放入 sum 变量中,最后检查我们是否执行过,但主要问题是 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    

【问题讨论】:

    标签: assembly x86 x86-16


    【解决方案1】:

    感谢我的朋友的帮助,我找到了问题。我们应该更换 mov sum[si+1], al 代替 mov sum[si+2],al

    【讨论】:

    • 当您的问题得到充分回答时,您应该接受现场给出的最佳答案,即使是您自己的! (这会给你一个徽章)
    猜你喜欢
    • 2016-11-04
    • 2013-08-19
    • 2017-10-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多