0

if data input PORT A=08H then data output PORT B=0FH, and if the data input PORT A = 80H then data output PORT B = F0H , other than these the output PORT B = 00H Here is my code

      LD     A, 4FH
      OUT    (82H), A
      LD     A, 0FH
      OUT    (83H), A

LOOP:   IN     A, (80H)
        CP     08H
        JRNZ   STATE1
        LD     B,0FH
        JR     RESULT
STATE1: CP     80H
        JRNZ   STATE2
        LD     B,F0H
        JR     RESULT
STATE2: LD     B,00H
RESULT: OUT    (81H), A
        JP     LOOP

Error : unrecognized instruction. 'JRNZ +-'

Michael
  • 57,169
  • 9
  • 80
  • 125

1 Answers1

3

The standard Z-80 mnemonics separate condition codes from the opcode. In other words, JRNZ is not a valid Z-80 opcode. You should separate it like this:

    JR    NZ,STATE1
...
    JR    NZ,STATE2

Incidentally, there's a bug in your program. You need to load register A with B before doing the output.

RESULT: LD     A,B
        OUT    (81H), A
        JP     LOOP

Or you could use the OUT (C),reg variant:

RESULT: LD     C,81H
        OUT    (C),B
        JP     LOOP

You can also make the program a little shorter if you load the output value in anticipation of matching the input. Like so:

LOOP:   IN     A,(80H)
        LD     B,0FH
        CP     08H
        JR     Z,RESULT
        LD     B,F0H
        CP     80H
        JR     Z,RESULT
        LD     B,00H
RESULT: LD     A,B
        OUT    (81H),A
        JP     LOOP
George Phillips
  • 4,564
  • 27
  • 25