Consider the last 2 digits of your registration number as a decimal. Write the code to check if it is even
or odd. Depending on the result, increment the original number once if it is even; decrement if the original
number is odd.
; DosBox
DATA SEGMENT
MSG_ENTER DB 10,13,"Enter the last 2 digits of your registration number as a decimal number: ",10,13,"$"
answer: db 10,13,"Answer: "
num1 DB 0
num2 DB 0
db '$'
DATA ENDS
CODE SEGMENT
ASSUME DS:DATA,CS:CODE
START:
MOV AX,DATA
MOV DS,AX
LEA DX,MSG_ENTER ; "Enter ..."
MOV AH,9 ; Display string
INT 21H
MOV AH,1 ; Waiting for a key press
INT 21H
; AL = ASCII code of key pressed
mov num1, al
MOV AH,1 ; Waiting for a key press
INT 21H
; AL = ASCII code of key pressed
mov num2, al
and al,01h
cmp al,0
jz _even
_odd:
dec num2
jmp EXIT_PROG
_even:
inc num2
EXIT_PROG:
LEA DX,answer
MOV AH,9
INT 21H
MOV AH,4CH
INT 21H
CODE ENDS
END START
Comments
Leave a comment