COAL ASSIGNMENT
Q1
.model small
.stack 100h
.data
prompt1 db 'Enter first number: $'
prompt2 db 'Enter second number: $'
result_msg db 'The result is: $'
newline db 0Dh, 0Ah, '$'
num1 db 0
num2 db 0
result db 0
.code
main:
mov ax, @data
mov ds, ax
lea dx, prompt1
mov ah, 09h
int 21h
lea dx, newline
mov ah, 09h
int 21h
lea dx, num1
mov ah, 01h
int 21h
sub al, '0'
mov bl, al
lea dx, prompt2
mov ah, 09h
int 21h
lea dx, newline
mov ah, 09h
int 21h
lea dx, num2
mov ah, 01h
int 21h
sub al, '0'
mov cl, al
add bl, cl
lea dx, result_msg
mov ah, 09h
int 21h
lea dx, newline
mov ah, 09h
int 21h
add bl, '0'
mov dl, bl
mov ah, 02h
int 21h
lea dx, newline
mov ah, 09h
int 21h
mov ah, 4Ch
int 21h
end main
Q2
.model small
.stack 100h
.data
prompt db 'Enter a character: $'
newline db 0Ah, 0Dh, '$' ; Newline (carriage return + line feed)
.code
main:
; Initialize data segment
mov ax, @data
mov ds, ax
; Display the prompt message
mov ah, 09h ; DOS function to display string
lea dx, prompt ; Load address of the prompt string
int 21h ; Call interrupt 21h to print the string
; Read a single character from the user
mov ah, 01h ; DOS function to read a single character
int 21h ; Call interrupt 21h to get the character
mov dl, al ; Move the input character to DL (for printing)
; Print newline (next line)
mov ah, 09h ; DOS function to display string
lea dx, newline ; Load address of newline string
int 21h ; Call interrupt 21h to print newline
; Display the character
mov ah, 02h ; DOS function to print a character
int 21h ; Call interrupt 21h to display character in DL
; Exit the program
mov ah, 4Ch ; DOS function to terminate program
int 21h ; Call interrupt 21h to exit
end main