odd number

Assembly program to check if a number is even or odd

To check if a number is even, we use its least significant bit (LSB) number. It is the rightmost or the leftmost digit in a binary number. If this LSB is 1 then the given number is even, otherwise its even.

 

When the following program is executed, it takes a number input from user and displays that if given number is even or odd.

.model small
.stack 100h
.data

ev db 'Even$'
od db 'Odd$'
.code
main proc
mov ax,@data
mov ds,ax
mov ah,1
int 21h
mov bl,2
div bl
cmp ah,0
je IsEven
mov dx,10
mov ah,2
int 21h
mov dx,13
mov ah,2
int 21h
mov dx,offset od
mov ah,9
int 21h
mov ah,4ch
int 21h
IsEven:
mov dx,10
mov ah,2
int 21h
mov dx,13
mov ah,2
int 21h
mov dx,offset ev
mov ah,9
int 21h
mov ah,4ch
int 21h

main endp
end main

Leave a Reply

Your email address will not be published. Required fields are marked *