Question
Hello, this is assembly language, please fix this code, the code gives an error in line 85 for block nesting error and in line 91
Hello, this is assembly language, please fix this code, the code gives an error in line 85 for block nesting error and in line 91 theres a warning that operand types must match. The program must ask the user for 2 numbers from 0 to 9, then it should ask the user if it wants to either add, subtract, divide or multiply these 2 numbers. Then calculate accordingly and display the result. When the user inputs the arithmetic operation it should be its respective symbol.
.model small .stack 100h
.data result db ? message db 'The result is: $'
.code
MAIN PROC mov ax, @data mov ds, ax
call GET_NUMBERS call GET_OPERATION call PERFORM_OPERATION call SHOW_RESULT
mov ah, 4ch int 21h
MAIN ENDP
GET_NUMBERS PROC mov dx, OFFSET firstNumberMessage call DISPLAY_MESSAGE call READ_NUMBER mov firstNumber, al
mov dx, OFFSET secondNumberMessage call DISPLAY_MESSAGE call READ_NUMBER mov secondNumber, al
GET_NUMBERS ENDP
GET_OPERATION PROC mov dx, OFFSET operationMessage call DISPLAY_MESSAGE call READ_OPERATION
GET_OPERATION ENDP
PERFORM_OPERATION PROC mov cl, operation cmp cl, '+' je ADDNUM
cmp cl, '-' je SUBTRACT
cmp cl, '*' je MULTIPLY
cmp cl, '/' je DIVIDE
PERFORM_OPERATION ENDP
ADDNUM: mov al, firstNumber add al, secondNumber jmp SAVE_RESULT
SUBTRACT: mov al, firstNumber sub al, secondNumber jmp SAVE_RESULT
MULTIPLY: mov al, firstNumber mul secondNumber jmp SAVE_RESULT
DIVIDE: mov al, firstNumber xor ah, ah div secondNumber jmp SAVE_RESULT
SAVE_RESULT: mov result, al
SAVE_RESULT ENDP
SHOW_RESULT PROC mov dx, OFFSET message call DISPLAY_MESSAGE
mov dx, result add dx, '0' call DISPLAY_CHAR
call NEW_LINE
SHOW_RESULT ENDP
DISPLAY_MESSAGE PROC mov ah, 9 int 21h
DISPLAY_MESSAGE ENDP
DISPLAY_CHAR PROC mov ah, 2 int 21h
DISPLAY_CHAR 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