I need to read and print the numbers stored in two variables (I'm doing a menu program) but when I print them it prints the small letters from the ASCII table ( like a,b,c instead of 2,3,4). I know I'm supposed to substract 48 and multiply but I didn't find a great solution on how to implement that transformation in my program. I'm using Assembly x86, TASM.
This is the code from reading the inputs:
scriere:
mov dx, offset prompt1
mov ah, 9
int 21h
input_x:
mov bx, offset x ; point BX to the start of the array x
mov cx, 10 ; set the counter to the number of elements in the array x
input_loop1:
mov ah, 01h ; function to read a single character
int 21h ; call DOS function
mov [bx], al ; store the character in the current array element
inc bx ; move to the next array element
loop input_loop1 ; repeat until counter reaches 0
jmp input_y
input_y:
mov dx, offset prompt2
mov ah, 9
int 21h
mov bx, offset y ; point BX to the start of the array y
mov cx, 10 ; set the counter to the number of elements in the array y
input_loop2:
mov ah, 01h ; function to read a single character
int 21h ; call DOS function
mov [bx], al ; store the character in the current array element
inc bx ; move to the next array element
loop input_loop2 ; repeat until counter reaches 0
jmp bucla
and the problem I think comes from my printing code:
afisare:
mov dx, offset prompt3
mov ah, 9
int 21h
print_x:
mov bx, offset x ; point BX to the start of the array x
mov cx, 10 ; set the counter to the number of elements in the array x
print_loop1:
mov dl, [bx] ; move the value of the current array element to DL
add dl, 48 ; convert the number to its ASCII equivalent
mov ah, 02h ; function to print a single character
int 21h ; call DOS function
inc bx ; move to the next array element
loop print_loop1 ; repeat until counter reaches 0
jmp print_y
print_y:
mov dx, offset prompt4
mov ah, 9
int 21h
mov bx, offset y ; point BX to the start of the array y
mov cx, 10 ; set the counter to the number of elements in the array y
print_loop2:
mov dl, [bx] ; move the value of the current array element to DL
add dl, 48 ; convert the number to its ASCII equivalent
mov ah, 02h ; function to print a single character
int 21h ; call DOS function
inc bx ; move to the next array element
loop print_loop2 ; repeat until counter reaches 0
jmp bucla ; return to main loop