Assuming that the trainer kit has a display unit connected to port 0 and the user will input the arbitrary number through port 1, the following code can be used:
MOV AH, 01 ; load input from port 1
INT 21H ; read character from port 1
SUB AL, 30H ; convert ASCII to binary
AND AL, 01H ; check if LSb is set (odd number)
JZ EVEN ; jump to even number conversion if LSb is not set
ADD AL, 1 ; add 1 to convert odd number to even number
JMP DISPLAY ; jump to display result
EVEN:
SUB AL, 1 ; subtract 1 to convert even number to odd number
DISPLAY:
ADD AL, 30H ; convert binary to ASCII
MOV AH, 02 ; prepare for output to port 0
MOV DL, AL ; copy result to output register
MOV DX, 0080H ; select port 0 for output
INT 21H ; write result to port 0
The program works as follows:
1. Load input from port 1 and convert it from ASCII to binary.
2. Check whether the least significant bit (LSb) of AL is set, which determines whether the input is an odd or even number.
3. If the input is an odd number, add 1 to convert it to the next larger even number.
4. If the input is an even number, subtract 1 to convert it to the next smaller odd number.
5. Convert the result back to ASCII and output it to port 0 for display.
Note: This program assumes that the input number is a single digit (0-9) and does not perform any error checking. Additional code would be required to handle invalid input.
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.
1 answer