The second digit of my first number has the same meaning as the first digit of the second number. I do not know why

I am new to assembly language. I'm trying to add 2 integers that are only 2 digits, but whenever I try to access my second digit in num1, it mysteriously accesses the first digit of num2. I need help! I really don't know why. I am using TASM btw.

This is my code.

;-----------------------
.model small
.stack 
.data

num db ?
num2 db ?
result db ?

prompt1 db "Enter 1st number: $"
prompt2 db "Enter 2nd number: $"
prompt3 db "Addition: $"

.code

main proc

;use the data segment
mov ax, @data
mov ds, ax
mov es, ax

;-------input first number--------------------  

;setcursor
mov ah, 02
mov dh, 00h
mov dl, 00h
int 10h

mov ah, 09
lea dx, prompt1
int 21h

mov cx, 02
lea si, num

loop1:
    mov ah, 07
    int 21h

    cmp al, 0Dh
    je outA

    cmp al, '0'
    jge True_A
    jmp false

    True_A:
        cmp al, '9'
        jle True_B
        jmp false


    True_B:
        mov ah, 02
        mov dl, al
        int 21h

        mov [si], al
    jmp next

    next:
    inc si
    dec cx      

    false:

jnz loop1

outA:

mov bl, '$'
mov [si], bl

;--------input 2nd number-----------------------------

;setcursor
mov ah, 02
mov dh, 02h
mov dl, 00h
int 10h

mov ah, 09
lea dx, prompt2
int 21h

mov cx, 02
lea di, num2

loop2:
    mov ah, 07
    int 21h

    cmp al, 0Dh
    je outB

    cmp al, '0'
    jge True_C
    jmp falseA

    True_C:
        cmp al, '9'
        jle True_D
        jmp falseA

    True_D:
        mov ah, 02
        mov dl, al
        int 21h

        mov [di], al
    jmp nextA

    nextA:
    inc di
    dec cx      

    falseA:
jnz loop2

outB:

mov bl, '$'
mov [di], bl

;-------------------------------------- 

mov ah, 02
mov dh, 05h
mov dl, 00h
int 10h

mov ah, 02
mov dl, num + 1
int 21h


mov ax, 4c00h
int 21h

main endp
end main

      

+3


source to share


1 answer


num db ?
num2 db ?
result db ?

      

Both of your routines to enter a 2-digit number write 3 bytes into memory. First digit, second digit, then $ . But for each number, you have only defined one byte of memory. Just change the definitions accordingly.



num    db ?,?,?
num2   db ?,?,?
result db ?,?,?,?

      

I would suggest giving an extra byte of storage because it is possible to add 3 digits. The maximum value will be 99 + 99 = 198

+3


source







All Articles