Assembly Program:
MOV AL, 10100101b ; Load AL by an arbitrary number
MOV BL, AL ; Copy AL to BL
AND BL, 00000001b ; Mask the least significant bit
CMP BL, 0 ; Check if the least significant bit is 0
JE EVEN ; If 0, jump to EVEN
MOV P0, #01H ; If not 0, transfer 01H to Port 0 and exit
JMP DONE
EVEN:
MOV P0, #80H ; Transfer 80H to Port 0 and exit
DONE:
HLT ; End the program
Machine Code:
B0 A5 ; MOV AL, 10100101b
8A C3 ; MOV BL, AL
24 01 ; AND BL, 00000001b
80 F3 00 ; CMP BL, 0
74 03 ; JE EVEN
74 01 ; JMP DONE
D3 1E 00 ; EVEN: MOV P0, #80H
F4 ; DONE: HLT
Write an assembly program that :
Load AL by an arbitrary number, if there is parity even, transfer 80H to the Port 0, and if there is parity odd, transfer 01H to the Port 0.
Convert the Assembly Program to Machine Code.
3 answers
in the machine code, you forgot
MOV P0, #01H
after the 74 03 ; JE EVEN
MOV P0, #01H
after the 74 03 ; JE EVEN
You are correct, thank you for pointing that out. Here is the corrected machine code:
B0 A5 ; MOV AL, 10100101b
8A C3 ; MOV BL, AL
24 01 ; AND BL, 00000001b
80 F3 00 ; CMP BL, 0
74 03 ; JE EVEN
D3 1E 01 ; MOV P0, #01H
EB 02 ; JMP DONE
D3 1E 80 ; EVEN: MOV P0, #80H
F4 ; DONE: HLT
B0 A5 ; MOV AL, 10100101b
8A C3 ; MOV BL, AL
24 01 ; AND BL, 00000001b
80 F3 00 ; CMP BL, 0
74 03 ; JE EVEN
D3 1E 01 ; MOV P0, #01H
EB 02 ; JMP DONE
D3 1E 80 ; EVEN: MOV P0, #80H
F4 ; DONE: HLT