.model small
.stack 100h
.data
input_buffer1 db 10 DUP (‘$’) ; Define a buffer to store the first input string
input_buffer2 db 10 DUP (‘$’) ; Define a buffer to store the second input string
message1 db ‘Enter the first integer: $’ ; Prompt message for the first input
message2 db ‘Enter the second integer: $’ ; Prompt message for the second input
newline db 13, 10, ‘$’ ; Newline character to print a newline
result_message db ‘The sum is: $’ ; Message for printing the sum
.code
main proc
mov ax, @data ; Load the address of the data segment into AX
mov ds, ax ; Set DS to point to the data segment
; Prompt for the first input
mov ah, 09h
mov dx, offset message1
int 21h
; Read the first input
mov ah, 0Ah ; Function to read a string
mov dx, offset input_buffer1
int 21h ; Call interrupt 21h
; Print a newline character
mov ah, 09h
mov dx, offset newline
int 21h
; Prompt for the second input
mov ah, 09h
mov dx, offset message2
int 21h
; Read the second input
mov ah, 0Ah ; Function to read a string
mov dx, offset input_buffer2
int 21h ; Call interrupt 21h
; Convert the first input to integer
mov si, offset input_buffer1 + 2 ; Skip the first two bytes (length and '$')
mov al, [si] ; Load the first character
sub al, '0' ; Convert ASCII character to integer
mov bl, al ; Save the integer in BL
; Convert the second input to integer
mov si, offset input_buffer2 + 2 ; Skip the first two bytes (length and '$')
mov al, [si] ; Load the first character
sub al, '0' ; Convert ASCII character to integer
add bl, al ; Add the second input (AL) to the first input (BL)
; Print a newline character
mov ah, 09h
mov dx, offset newline
int 21h
; Print the sum
mov ah, 09h
mov dx, offset result_message
int 21h
; Convert the sum to ASCII and print
mov dl, bl ; Move the result to DL for printing
add dl, '0' ; Convert integer to ASCII character
mov ah, 02h ; Function to print a character
int 21h ; Call interrupt 21h
end main
; Convert the sum to ASCII and print
mov dl, bl ; Move the result to DL for printing
add dl, ‘0’ ; Convert integer to ASCII character
mov ah, 02h ; Function to print a character
int 21h ; Call interrupt 21h
I think problem here, I cant figure how can I print more than one digit.
hadeel Jalil is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.