153k views
0 votes
Write an assembly code

Read 1 byte number (between 0 and 9). Write a program that prints:

It's ODD

if input is odd and prints

It's EVEN if input is even

1 Answer

4 votes

; Read input byte

MOV AH, 01h ; Set up input function

INT 21h ; Read byte from standard input, store in AL

; Check if input is even or odd

MOV BL, 02h ; Set up divisor

DIV BL ; Divide AL by BL, quotient in AL, remainder in AH

CMP AH, 00h ; Compare remainder with zero

JNE odd ; Jump to odd if remainder is not zero

JMP done ; Jump to done if remainder is zero

odd: ; Odd case

MOV DX, OFFSET message_odd ; Set up message address

JMP print

even: ; Even case

MOV DX, OFFSET message_even ; Set up message address

print: ; Print message

MOV AH, 09h ; Set up output function

INT 21h ; Print message

done: ; End of program

User Franco Ponticelli
by
7.4k points