Model Stack

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 2

Code

.MODEL SMALL
.STACK 100H
.DATA

msg db "Raj mhatre 2547",13,3,"$"

MSG1 DB 0dh,0ah, "Number is odd: ODD$"


MSG2 DB 0dh,0ah,"Number is even: EVEN$"
NUM DB ?
prompt DB 0dh,0ah, 'Enter a number: $'

.CODE
start:
mov ax, @data
mov ds, ax
mov dx, offset msg
mov ah, 09h
int 21h
MOV CX, 5 ; Assume that the user will enter 5 numbers

INPUT:
; Display message to enter a number
MOV AH, 09H
LEA DX, prompt
INT 21H

; Read a single character from the keyboard


MOV AH, 01H
INT 21H
SUB AL, '0' ; Convert ASCII to numerical value

; Check if the input number is valid


CMP AL, 9
JG INPUT_ERROR

; Store the input number


MOV NUM, AL

; Check if the number is odd or even


TEST AL, 1
JNZ ODD

; Even
MOV DX, OFFSET MSG2
JMP DISPLAY

ODD:
; Odd
MOV DX, OFFSET MSG1
DISPLAY:
; Display the result
MOV AH, 09H
INT 21H

LOOP INPUT

; Exit the program


MOV AH, 4CH
INT 21H

INPUT_ERROR:
; Display an error message
MOV DX, OFFSET error_msg
MOV AH, 09H
INT 21H

; Exit the program


MOV AH, 4CH
INT 21H

error_msg DB 'Invalid input. Please enter a number between 0 and


9.$'
END start

You might also like