ORG 0DFBCH
LD C,4;FOUR PORTS
CALL SAMPLE
LD HL,PORT0
LD (HL),D
LD C,5
CALL SAMPLE
LD HL,PORT1
LD (HL),D
LD C,6
CALL SAMPLE
LD HL,PORT2
LD (HL),D
LD C,7
CALL SAMPLE
LD HL,PORT3
LD (HL),D
RET 
SAMPLE: LD HL,0000H
LD D,0
LD B,0
LDFE8:LD A,C
OUT (38H),A
LD A,7
LD A,7
LDFEF:DEC A
CP 0
JR NZ,LDFEF
IN A,(38H)
LD E,A
ADD HL,DE
DJNZ LDFE8
LD D,H
RET 
PORT0:DB 0
PORT1:DB 0
PORT2:DB 0
PORT3:DB 0
END
 0
JR NZ,LDFEF
IN A,(38H)
LD E,A
ADD HL,DE
DJNZ LDFE8
LD D,H
RET 
PORT0: