Question
fix code .model small .stack 100h .data prompt1 db 10,13,'Enter first digit: $' prompt2 db 10,13,'Enter second digit: $' prompt3 db 10,13,'Enter operation (+, -,
fix code
.model small .stack 100h
.data prompt1 db 10,13,'Enter first digit: $' prompt2 db 10,13,'Enter second digit: $' prompt3 db 10,13,'Enter operation (+, -, /, *): $' result dw ?
.code main proc mov ax, @data mov ds, ax
call GET_FIRST_DIGIT call GET_SECOND_DIGIT call GET_OPERATION
; show the result call SHOW_RESULT ;call WAIT_FOR_KEY ret main endp
; get the first digit GET_FIRST_DIGIT proc ; display the prompt lea dx, prompt1 call DISPLAY_PROMPT
; get the digit call GET_DIGIT mov bx, ax ret GET_FIRST_DIGIT endp
; get the second digit GET_SECOND_DIGIT proc ; display the prompt lea dx, prompt2 call DISPLAY_PROMPT
; get the digit call GET_DIGIT mov cx, ax ret GET_SECOND_DIGIT endp
; get the operation GET_OPERATION proc ; display the prompt lea dx, prompt3 call DISPLAY_PROMPT
; get the operation call GET_CHAR mov ah, 0 cmp al, '+' je ADDNUM cmp al, '-' je SUBTRACT cmp al, '*' je MULTIPLY cmp al, '/' je DIVIDE
ADDNUM: add ax, bx jmp SAVE_RESULT
SUBTRACT: sub ax, bx jmp SAVE_RESULT
MULTIPLY: mov ax, bx mul cx jmp SAVE_RESULT
DIVIDE: mov ax, bx div cx jmp SAVE_RESULT
SAVE_RESULT: mov result, ax ret GET_OPERATION endp
; display the result SHOW_RESULT proc ; display the result mov dx, result call DISPLAY_NUMBER ret SHOW_RESULT endp
; display a prompt DISPLAY_PROMPT proc ; display the prompt mov ah, 9 int 21h ret DISPLAY_PROMPT endp
; get a digit GET_DIGIT proc ; get the digit call GET_CHAR sub al, 48 mov ah, 0 ret GET_DIGIT endp
; get a character GET_CHAR proc ; get the character mov ah, 1 int 21h ret GET_CHAR endp
; display a number DISPLAY_NUMBER proc ; display the number call DISPLAY_DIGIT ret DISPLAY_NUMBER endp READ_NUMBER PROC mov ah, 1 int 21h sub al, '0'
READ_NUMBER ENDP
READ_OPERATION PROC mov ah, 1 int 21h
READ_OPERATION ENDP
NEW_LINE PROC mov dx, OFFSET newLine call DISPLAY_MESSAGE
NEW_LINE ENDP
.data firstNumberMessage db 'Enter the first number: $' secondNumberMessage db 'Enter the second number: $' operationMessage db 'Enter the operation (+, -, *, /): $' newLine db 13, 10, '$' firstNumber db ? secondNumber db ? operation db ?
END MAIN
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started