Here is my code. The error always says that relative jump out of range by 001Ch and 001Bh bytes.
.model small
.stack 1000h
.data
prompt db "Welcome to the Main Menu", 13, 10, "1. Adding 2 numbers", 13, 10, "2. Odd and Even", 13, 10, "3. Positive and Negative", 13, 10, "4. Exit", 13, 10,"Enter your choice: $"
invalid db "Invalid choice. Please try again.$"
newline db 13, 10, "$"
msg1 DB 10,13,'Enter the first digit: $'
msg2 DB 10,13,'Enter the second digit: $'
msg3 DB 10,13,'The sum is: $'
msg4 DB 10,13,'Enter first number: $'
msg5 DB 10,13,'Enter second number: $'
msg6 DB 10,13,'The results are: $'
even_msg db ' is even.$'
odd_msg db ' is odd.$'
x DB ?
y DB ?
sum DB ?
.code
start:
; Initialize data segment
mov ax, @data
mov ds, ax
display_menu:
; Display welcome message and menu
mov ah, 09h
lea dx, newline
int 21h
mov ah, 09h
lea dx, prompt
int 21h
read_choice:
; Read user input
mov ah, 01h
int 21h
sub al, '0' ; Convert ASCII digit to numeric value
; Check user's choice
cmp al, 1
je option1_selected
cmp al, 2
je option2_selected
cmp al, 3
je option3_selected
cmp al, 4
je exit_program
jmp invalid_choice
option1_selected:
; Display message to enter first digit
mov ah, 09h
lea dx, msg1
int 21h
; Read first digit
mov ah, 01h
int 21h
sub al, '0'
mov x, al
; Display message to enter second digit
mov ah, 09h
lea dx, msg2
int 21h
; Read second digit
mov ah, 01h
int 21h
sub al, '0'
mov y, al
; Calculate sum
mov al, x
add al, y
mov sum, al
; Display sum
mov ah, 09h
lea dx, msg3
int 21h
; Display sum value
mov dl, sum
add dl, '0'
mov ah, 02h
int 21h
jmp short display_menu ; Return to main menu
option2_selected:
; Display prompts for the numbers
mov ah, 9
lea dx, msg4
int 21h
; Read the first number
mov ah, 1
int 21h
mov bl, al ; Store the first number
; Display prompts for the numbers
mov ah, 9
lea dx, msg5
int 21h
; Read the second number
mov ah, 1
int 21h
mov cl, al ; Store the second number
; Display result message
mov ah, 9
lea dx, msg6
int 21h
; Display the first number
mov ah, 2
mov dl, bl
int 21h
; Display whether the first number is even or odd
mov ah, 9
mov al, bl
test al, 1
jz first_even
lea dx, odd_msg
int 21h
jmp second_check
first_even:
lea dx, even_msg
int 21h
; Display the second number
second_check:
mov ah, 2
mov dl, cl
int 21h
; Display whether the second number is even or odd
mov ah, 9
mov al, cl
test al, 1
jz second_even
lea dx, odd_msg
int 21h
second_even:
lea dx, even_msg
int 21h
jmp short display_menu ; Return to main menu
jmp display_menu
1