Reputation: 11
Program to make output port B = FFH, if and only if input port A = 01H (another input then output is 00)
Here my code:
LD A, 4FH
OUT (82H), A
LD A, 0FH
OUT (83H), A
LOOP: IN A,(80H)
CP 01H
JR NZ,S1
LD A,00H
S1: LD A,FFH
OUT (81H),A
JP LOOP
the problem is when i give input another than 01, the output still FF
Upvotes: 0
Views: 150
Reputation: 117308
I'm a bit rusty since I haven't used Z80 assembler in 35 years, but it seems to me like you'll LD A,FFH
before output every loop.
Consider adding a label (S2
) and jumping to that after having loaded A
with 00H
- and haven't you swapped the JR NZ
logic? JR NZ
jumps if CP 01H
doesn't set Z
.
LD A, 4FH
OUT (82H), A
LD A, 0FH
OUT (83H), A
LOOP: IN A,(80H)
CP 01H
JR NZ,S1 ; jump to S1 if 01 was not read
LD A,FFH ; we got 01, load FF
JR S2 ; ... and jump to S2
S1: LD A,00H ; will only be reached if 01 was not read
S2: OUT (81H),A
JP LOOP ; could probably be JR LOOP
Upvotes: 1