Assuming the trainer kit has a switch connected to port 1 to input the arbitrary number and a 7-segment display connected to port 0 to output the converted number, the following is an example of an assembly program that fulfills the requirements:
ORG 0000h ; start at address 0000h
start:
MOV A, P1 ; load arbitrary number from port 1 to AL
ANL A, #1h ; check the least significant bit to see whether it is odd/even
JZ even_num ; jump to even_num if it is even (LSB=0)
INC A ; add 1 to odd number to get the next larger even number
JMP display ; jump to display the converted number
even_num:
DEC A ; subtract 1 from even number to get the previous smaller odd number
display:
MOV P0, A ; move the converted number to port 0 to display on the 7-segment display
SJMP $ ; loop indefinitely
END ; end of program
Part B) Write an 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.
1 answer