-1

I can't find the code where I can put edit so that I can add two digit numbers instead of 1 digit numbers, here's the code:

.model small
.stack 100h
.data

first db 13,10, 'Enter 1st Number: $'
second db 13,10, 'Enter 2nd Number: $'
result db 13,10, 'Result: $'
invalid db 13,10, 'Invalid Number!!! $'

.code

start:
        mov ax,03
        int 10h

        mov ax,@data
        mov ds,ax

mn:
        mov dx, offset first
        mov ah,9
        int 21h

        mov ah,1
        int 21h

        mov cl,al

        cmp al,30h
        jl nvalid
        cmp al,39h
        jg nvalid
        jmp proceed

nvalid:
        mov dx,offset invalid
        mov ah,9
        int 21h
        jmp mn

proceed:
        sub cl,30h

        mov dx,offset second
        mov ah,9
        int 21h
        mov ah,1
        int 21h

        cmp al,30h
        jl nvalid
        cmp al,39h
        jg nvalid
        sub al,30h

        xor ah,ah
        add al,cl
        aaa

        mov cx,ax
        add cx,3030h
        mov dx, offset result
        mov ah,9
        int 21h

        mov ah,2
        mov dl,ch
        int 21h

        mov dl,cl
        int 21h

exit:
        mov ah,4ch
        int 21h

end start
Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
user3089342
  • 1
  • 1
  • 1
  • 1

1 Answers1

2

After looking at your code, your real question is not "how do I add two-digit numbers together" (that's obvious, use the add instruction).

Your real question is "How do I display a two digit number using int 21h, ah=09h?"

The answer is: you need to display each number separately, by dividing the original number by increasing powers of 10 until you get zero. Add 30h ('0') to each result and display that character.

Related:

Community
  • 1
  • 1
Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328