Given with the code of an 8051, how does a JZ instruction work? Why is it essential to add CPL A before and after the JZ instruction?
ORG 0000H
MAIN:
CLR A
INPUT:
CALL DELAY
MOV A, P2
CPL A ; complement the content of the register Accumulator
JZ INPUT ; jump to INPUT if no switch is pressed
CPL A; complement the content of the register Accumulator
MOV P1, A
CALL ROTATE
ROTATE:
RL A
MOV P1, A
CALL ROT
DELAY:
MOV R0, #0FH
L1: MOV R1, #01H
L2: MOV R2, #01H
DJNZ R1
DJNZ R0,
RET
END
JZ what it does is the program control will jump to a specified address pointed by the Label if the Accumulator is zero.
Here CPL A is added before and after the JZ instruction because JZ instruction works with the Accumulator register and here we need to jump if no switch is pressed. That is when P2 is 1 therefore if we complement the Accumuator after moving the content of the P2 to A then that means whenever P2 is 1 then do the jump otherwise dont perform Jump.
To Retain the old value of Accumulator CPLA is again done after the JZ instruction.
Get Answers For Free
Most questions answered within 1 hours.