【问题标题】:how to add two number using emu8086如何使用emu8086添加两个数字
【发布时间】:2016-06-15 08:40:04
【问题描述】:

在代码下方添加两个偶数,输出也将低于 10,但我要知道并显示输出的挑战将是 10 那么这个概念是什么?我如何添加两个数字但输出显示数字扩展为 10。 你能给出一些想法吗? .model 小 .stack 100h 。数据 msg1 db "$ 的总和" msg2 数据库“和$” msg3 数据库“是:$” 。代码 主进程

mov ax,@data
mov ds,ax

mov ah,9
lea dx,msg1
int 21h
         
mov ah, 2
mov dl,20h
int 21h

mov ah,1
int 21h
mov bl,al 
    
mov ah,9
lea dx,msg2
int 21h  

mov ah, 2
mov dl,20h
int 21h

mov ah,1
int 21h
mov cl,al

mov ah,9
lea dx,msg3
int 21h

mov ah, 2
mov dl,20h
int 21h

mov ah,2
mov dl,20h
int 21h    

add bl,cl
sub bl,30h

mov ah,2
mov dl,bl
int 21h

main endp
end main

【问题讨论】:

    标签: emu8086


    【解决方案1】:

    由于您仍在处理从“0”到“9”的单个字符输入,因此总和可以是 18 (9 + 9)。对大于 9 的值进行简单检查即可:

        mov  ah, 2    ;DOS display function
        add  bl, cl   ;Sum of 2 characters
        sub  bl, 30h  ;Remove the extra 30h
        cmp  bl, "9"
        jbe  PrintDigit
        mov  dl, "1"
        int  21h
        sub  bl, 10
    PrintDigit:
        mov  dl, bl
        int  21h
    

    为什么在字符串输出后直接输出一个空格字符?你知道你可以很容易地把这个空格字符放在消息中!

    msg1 db "The sum of $"   <--- See the extra space before the $
    msg2 db "and $"          <--- See the extra space before the $
    msg3 db "is:  $"         <--- See the 2 extra spaces before the $
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-01-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多