Duplicate Question
The question on this page has been marked as a duplicate question.
Original Question
Write an assembly program that: - Load AL by an arbitrary number, - Check whether it is an odd/even number, - If it is an odd n...Question
3) Write a simple 8086 assembly program that:
- Load AL by an arbitrary number,
- Check whether it is an odd/even number,
- If it is an odd number, it will be converted to its next larger even number and will be shown in port 0 in the trainer kit.
- If it is an even number, it will be converted to its previous smaller odd number and will be shown in port 0 in the trainer kit.
- Load AL by an arbitrary number,
- Check whether it is an odd/even number,
- If it is an odd number, it will be converted to its next larger even number and will be shown in port 0 in the trainer kit.
- If it is an even number, it will be converted to its previous smaller odd number and will be shown in port 0 in the trainer kit.
Answers
There are no human answers yet.
Answered by
Bot
Here is a possible solution:
.MODEL SMALL
.STACK 100h
.DATA
number DB 17 ; the arbitrary number to work with
.CODE
MOV AX, @DATA ; initialize DS
MOV DS, AX
MOV AL, number ; load AL by the arbitrary number
AND AL, 01h ; check the least significant bit (LSB)
JZ even ; if it is zero, AL is even
; if it is one, AL is odd
ADD AL, 1 ; convert AL to the next larger even number
JMP show_result
even:
SUB AL, 1 ; convert AL to the previous smaller odd number
show_result:
MOV AH, 0 ; clear AH (not needed, but good practice)
MOV DX, 0 ; prepare DX for the OUT instruction
MOV DX, 8 ; select port 0 in the trainer kit (use your own value)
MOV BL, AL ; move the result to a safe place (optional)
OUT DX, AL ; send the result to port 0
MOV AH, 4Ch ; return control to DOS
INT 21h
END
.MODEL SMALL
.STACK 100h
.DATA
number DB 17 ; the arbitrary number to work with
.CODE
MOV AX, @DATA ; initialize DS
MOV DS, AX
MOV AL, number ; load AL by the arbitrary number
AND AL, 01h ; check the least significant bit (LSB)
JZ even ; if it is zero, AL is even
; if it is one, AL is odd
ADD AL, 1 ; convert AL to the next larger even number
JMP show_result
even:
SUB AL, 1 ; convert AL to the previous smaller odd number
show_result:
MOV AH, 0 ; clear AH (not needed, but good practice)
MOV DX, 0 ; prepare DX for the OUT instruction
MOV DX, 8 ; select port 0 in the trainer kit (use your own value)
MOV BL, AL ; move the result to a safe place (optional)
OUT DX, AL ; send the result to port 0
MOV AH, 4Ch ; return control to DOS
INT 21h
END
Submit Your Answer
We prioritize human answers over AI answers.
If you are human, and you can answer this question, please submit your answer.