0

When i input for example, 5 and 5, i get the output of " : " and i was wondering why?

INCLUDE Irvine32.inc

.data
dig1Msg     BYTE    "Enter first digit: ", 0
dig2Msg     BYTE    "Enter second digit: ", 0
sumMsg      BYTE    "Sum = ", 0
dig1        BYTE    ?
dig2        BYTE    ?
digSum      BYTE    ?


.code
main        PROC                    ; Start

        call    Clrscr

        LEA EDX, dig1Msg            ; Print "Enter first digit: "
        call    WriteString

        call    inDig               ; Input dig1
        mov dig1, AL
        call    outDig
        call    CRLF

        LEA EDX, dig2Msg            ; Print "Enter second digit: "
        call    WriteString

        call    inDig               ; Input dig2
        mov dig2, AL
        call    outDig
        call    CRLF
        
        mov AL, dig1            ; digSum = dig1 + dig2
        add AL, dig2
        mov digsum, AL
        
        LEA EDX, sumMsg         ; Print "Sum = "; digSum
        call    WriteString
        mov AL, digSum
        call    outDig  


        call    CRLF
        exit                    ; Stop
main        ENDP

;*******************
; Input digit
; input: none
; Output: digit returned in AL
;*******************

inDig       PROC                    ; Enter

        call    ReadChar            ; Input dig
        sub AL, '0'

        ret                 ; Exit
inDig       ENDP

;*******************
; Print digit
; input: value to print in AL register
; output: none
;*******************

outDig      PROC                    ; Enter

        add AL, '0'             ; Print dig
        call    WriteChar

        ret                 ; Exit
outDig      ENDP

        END main
Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
jcbh
  • 1
  • 1
  • 3
    The next ASCII character after '9' is ':'. If your output is one character you can't expect it to print two characters ('1' and '0'). – Guy Incognito Sep 19 '20 at 06:40
  • 0x35 + 0x35 - 0x30 = 0x3A which is a colon ':' Put a 5 and a 6 in and you will get a semicolon ';' and so on. http://www.asciitable.com – old_timer Sep 20 '20 at 06:42

0 Answers0