Assuming the trainer kit has a 7-segment display connected to port 0 and the arbitrary number is stored at memory location 500, the following assembly code can be used:
MOV AH, 0
MOV AL, [500] ; load the arbitrary number from memory
AND AL, 1 ; check if AL is odd or even
; if odd, convert to next even number
CMP AL, 1 ; check if AL is odd
JNE even ; if not, jump to even
; if odd, add 1 to make it even
INC AL
JMP display ; jump to display
; if even, convert to previous odd number
even:
DEC AL ; subtract 1 to make it odd
AND AL, 0FE ; clear the least significant bit to make it even
; display the result on port 0 using 7-segment display
display:
MOV DL, AL ; move the result to DL
MOV AH, 1 ; set AH to 1 to output to port 0
OUT 0, DL ; output the result to port 0
RET ; return from the program
Note: The code assumes that the trainer kit has a latch to hold the output on port 0 until the next value is written to it. If not, some delay may need to be added before returning from the program to allow time for the value to be displayed.
Write an assembly program (8086) that will Load AL by an arbitrary number, and 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.
1 answer