Hardware manual

The 8051 Instruction Set
Atmel 8051 Microcontrollers Hardware Manual 1-13
4316A–8051–01/04
done. If there is no interrupt in progress at the time RETI is executed, then the RETI is
functionally identical to RET.
Table 1-11 shows the list of conditional jumps available to the Atmel 8051 user. All of
these jumps specify the destination address by the relative offset method, and so are
limited to a jump distance of -128 to + 127 bytes from the instruction following the condi-
tional jump instruction. Important to note, however, the user specifies to the assembler
the actual destination address the same way as the other jumps: as a label or a 16-bit
constant.
There is no Zero bit in the PSW. The JZ and JNZ instructions test the Accumulator data
for that condition.
The DJNZ instruction (Decrement and Jump if Not Zero) is for loop control. To execute a
loop N times, load a counter byte with N and terminate the loop with DJNZ to the beginning
of the loop, as shown below for N = 10:
MOV COUNTER, # 10
LOOP:(begin loop)
*
*
*
(end loop)
DJNZ COUNTER, LOOP
(continue)
The CJNE instruction (Compare and Jump if Not Equal) can also be used for loop con-
trol as in Table 1-11. Two bytes are specified in the operand field of the instruction. The
jump is executed only if the two bytes are not equal. In the example of Figure 12, the two
bytes were the data in R1 and the constant 2AH. The initial data in R1 was 2EH. Every
time the loop was executed, R1 was decremented, and the looping was to continue until
the R1 data reached 2AH.
Another application of this instruction is in “greater than, less than” comparisons. The
two bytes in the operand field are taken as unsigned integers. If the first is less than the
second, then the Carry bit is set (1). If the first is greater than or equal to the second,
then the Carry bit is cleared.
1.10 Instruction Table Table 1-12 shows the Hex value of each instruction detailing the:
byte size
number of cycles
flags modified by the instruction
Table 1-11. Conditional Jumps in Atmel 8051 Devices
Mnemonic Operation Addressing Modes
Execution Time
@ 12MHz s)
DIR IND REG IMM
JZ rel Jump if A = 0 Accumulator only 2
JNZ rel Jump if A 0 Accumulator only 2
DJNZ <byte>,rel
Decrement and jump if
not zero
X X 2
CJNZ A,<byte>,rel Jump if A = <byte> X X 2
CJNE <byte>,#data,rel Jump if <byte> = #data X X 2