Check Odd or Even - Assembly Language - MASM


CHECK WHETHER A NUMBER IS ODD OR EVEN

Program:
.model small
.stack 200H
.data
msg1 DB 10,13,' Number is odd.$'
msg2 DB 10,13,' Number is even.$'
msg3 DB 10,13,'Enter the no:$'
newline DB 10,13,'$'
sum DW 0
count DW ?
num DW ?
.code
print MACRO msg
PUSH AX
PUSH DX
MOV AH,09H
MOV DX,offset msg
INT 21H
POP DX
POP AX
ENDM
.startup
print newline
print msg3
CALL readnumtoAX
MOV BL,02
DIV BL
CMP AH,00
JE even1
print newline
print msg1
JMP last
even1:
print newline
print msg2
last:
.exit
readnumtoAX PROC NEAR
PUSH BX
PUSH CX
MOV CX,10
MOV BX,00
back:
MOV AH,01H
INT 21H
CMP AL,'0'
JB skip
CMP AL,'9'
JA skip
SUB AL,'0'
PUSH AX
MOV AX,BX
MUL CX
MOV BX,AX
POP AX
MOV AH,00
ADD BX,AX
JMP back
skip:
MOV AX,BX
POP CX
POP BX
RET
readnumtoAX ENDP
END

Output:

F:\>od
Enter the no:135
Number is odd.
F:\>od
Enter the no:156
Number is even.


5 comments:

  1. can you please tell me how is it done?i mean the simulation

    ReplyDelete
  2. Thank you for this sir you save my life on my finals!

    ReplyDelete
  3. Very interesting thanks. I believe there's even more that could be on there! keep it up translation services

    ReplyDelete
  4. sir can you give me the code for the input of zero?

    ReplyDelete
  5. Nice article . you can use & operator for checking even or odd any number reference check even or odd without modulo

    ReplyDelete

Related Posts Plugin for WordPress, Blogger...