Question: FOR THE CODE BELOW, I AM GETTING THE FOLLOWING ERROR, PLEASE HELP ME FIX IT * * Error * * T 2 . asm (
FOR THE CODE BELOW, I AM GETTING THE FOLLOWING ERROR, PLEASE HELP ME FIX IT
Error Tasm Relative jump out of range by h bytes
; Single Digit Calculator
MODEL SMALL
STACK H
DATA
menumsg db DhAh
db Single Digit Calculator DhAh
db DhAh
db Addition DhAh
db Multiplication DhAh
db Subtraction DhAh
db Exit DhAh
db DhAh$
selectopmsg db "Please enter the operation for addition, etc.: $
numprompt db DhAh "Enter a single digit number : $
resultmsg db DhAh "The result is: $
errormsg db DhAh "INVALID INPUT! Enter a number between and $
exitmsg db DhAh "Exiting the program. Goodbye!", DhAh$
num db ; Variable for the first number
num db ; Variable for the second number
result db ; Variable for the result
operation db ; Variable to store operation choice
ten db ; Constant for division by
CODE
START:
MOV AX @data
MOV DS AX
; Call the main menu procedure
CALL MAINMENU
MAINMENU:
; Display the menu
MOV DX OFFSET menumsg
MOV AHh
INT h
; Prompt user for operation choice
MOV DX OFFSET selectopmsg
MOV AHh
INT h
; Read operation choice
MOV AH
INT H
SUB AL
CMP AL
JB INVALIDOPERATION
CMP AL
JA INVALIDOPERATION
MOV operation, AL
; Check if user selected to exit
CMP AL
JE EXITPROGRAM
; Call the function to get the first digit
CALL GETSINGLEDIGIT
MOV num AL
; Call the function to get the second digit
CALL GETSINGLEDIGIT
MOV num AL
; Perform the chosen operation
CALL PERFORMOPERATION
; Display the result
MOV DX OFFSET resultmsg
MOV AHh
INT h
CALL DISPLAYRESULT
; Return to main menu after calculation
JMP MAINMENU ; Return to the menu
INVALIDOPERATION:
MOV DX OFFSET errormsg
MOV AHh
INT h
JMP MAINMENU ; Return to the menu
GETSINGLEDIGIT PROC
; Prompt for a single digit
MOV DX OFFSET numprompt
MOV AHh
INT h
; Read digit
MOV AH
INT H
SUB AL
CMP AL
JL INVALIDINPUT
CMP AL
JG INVALIDINPUT
RET
INVALIDINPUT:
MOV DX OFFSET errormsg
MOV AHh
INT h
CALL GETSINGLEDIGIT ; Call again if input is invalid
GETSINGLEDIGIT ENDP
PERFORMOPERATION PROC
; Perform calculation based on operation
MOV AL num
MOV BL num
CMP operation,
JE ADDITION
CMP operation,
JE MULTIPLICATION
CMP operation,
JE SUBTRACTION
RET
ADDITION:
ADD AL BL
MOV result, AL
RET
MULTIPLICATION:
MUL BL
MOV result, AL
RET
SUBTRACTION:
SUB AL BL
MOV result, AL
RET
PERFORMOPERATION ENDP
DISPLAYRESULT PROC
; Check if result is a twodigit number
MOV AL result
CMP AL
JL DISPLAYSINGLEDIGIT
; Handle twodigit result
MOV BL AL ; Store result in BL
MOV AH
DIV ten
ADD AL ; Convert tens place to ASCII
MOV DL AL
MOV AHh
INT h ; Print tens digit
MOV AL BL ; Restore result in AL
MOV AH
DIV ten ; Get remainder in AH
MOV AL AH ; Move remainder to AL
ADD AL ; Convert ones place to ASCII
MOV DL AL
MOV AHh
INT h ; Print ones digit
RET
DISPLAYSINGLEDIGIT:
ADD AL ; Convert to ASCII
MOV DL AL
MOV AHh
INT h ; Print single digit result
RET
DISPLAYRESULT ENDP
EXITPROGRAM:
MOV DX OFFSET exitmsg
MOV AHh
INT h
MOV AHCh
INT h
END START
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
