Answer to Question #295681 in Assembler for Saju Maju

Question #295681

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.


1
Expert's answer
2022-02-09T10:40:43-0500
; 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

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be the first!

Leave a comment

LATEST TUTORIALS
New on Blog
APPROVED BY CLIENTS