Compare and Jump if Not Equal
Instruction | CJNE dest-byte,src-byte, rel |
---|---|
Function | Compare and Jump if Not Equal |
Description | CJNE compares the magnitudes of the first two operands and branches if their values are not equal. The branch destination is computed by adding the signed relative-displacement in the last instruction byte to the PC, after incrementing the PC to the start of the next instruction. The carry flag is set if the unsigned integer value of dest-byte is less than the unsigned integer value of src-byte; otherwise, the carry is cleared. Neither operand is affected. The first two operands allow four addressing mode combinations: the Accumulator may be compared with any directly addressed byte or immediate data, and any indirect RAM location or working register can be compared with an immediate constant. |
Example | The Accumulator contains 34H. Register 7 contains 56H. The first instruction in the sequence, CJNE R7, # 60H, NOT_EQ ; . . . . . . . . ;R7 = 60H. NOT_EQ: JC REQ_LOW ;IF R7 < 60H. ; . . . . . . . . ;R7 > 60H. sets the carry flag and branches to the instruction at label NOT_EQ. By testing the carry flag, this instruction determines whether R7 is greater or less than 60H. If the data being presented to Port 1 is also 34H, then the following instruction, WAIT: CJNE A, P1,WAIT clears the carry flag and continues with the next instruction in sequence, since the Accumulator does equal the data read from P1. (If some other value was being input on P1, the program loops at this point until the P1 data changes to 34H.) |
Variants | CJNE A, direct address, relative address CJNE A, #immediate data, relative address CJNE Rn, #immediate data, relative address CJNE @Ri, #immediate data, relative address |
Instruction | CJNE A, direct address, relative address |
---|---|
Bytes | 3 |
Cycles | 2 |
Encoding | 1 0 1 1 0 1 1 1 DA7...DA0 RA7...RA0 |
Operation | PC = PC + 3 IF A <> direct address PC = PC + relative address IF A < direct address C = 1 ELSE C = 0 |
Flags Affected | C AC F0 RS1 RS0 OV P |
Example | CJNE A, 60h, LABEL |
Bytes: Number of bytes required to encode the instruction. Cycles: Number of instruction cycles required to execute the instruction. Note that there are 12 oscillator cycles to one instruction cycle on a standard 8051. Encoding: Lists the byte encoding for the instruction. Operation: Lists, step-by-step, the operations performed by the instruction. Flags Affected: are highlighted in Bold |
Instruction | CJNE A, #immediate data, relative address |
---|---|
Bytes | 3 |
Cycles | 2 |
Encoding | 1 0 1 1 0 1 0 0 D7...D0 A7...A0 |
Operation | PC = PC + 3 IF A <> immediate data PC = PC + relative address IF A < immediate data C = 1 ELSE C = 0 |
Flags Affected | C AC F0 RS1 RS0 OV P |
Example | CJNE A, #01H, LABEL |
Bytes: Number of bytes required to encode the instruction. Cycles: Number of instruction cycles required to execute the instruction. Note that there are 12 oscillator cycles to one instruction cycle on a standard 8051. Encoding: Lists the byte encoding for the instruction. Operation: Lists, step-by-step, the operations performed by the instruction. Flags Affected: are highlighted in Bold |
Instruction | CJNE Rn, #immediate data, relative address |
---|---|
Bytes | 3 |
Cycles | 2 |
Encoding | 1 0 1 1 1 n n n D7...D0 A7...A0 |
Operation | PC = PC + 3 IF (Rn) <> immediate data PC = PC + relative address IF (Rn) < immediate data C = 1 ELSE C = 0 |
Flags Affected | C AC F0 RS1 RS0 OV P |
Example | CJNE R6, #12H, LABEL |
Bytes: Number of bytes required to encode the instruction. Cycles: Number of instruction cycles required to execute the instruction. Note that there are 12 oscillator cycles to one instruction cycle on a standard 8051. Encoding: Lists the byte encoding for the instruction. Operation: Lists, step-by-step, the operations performed by the instruction. Flags Affected: are highlighted in Bold |
Instruction | CJNE @Ri, #immediate data, relative address |
---|---|
Bytes | 3 |
Cycles | 2 |
Encoding | 1 0 1 1 0 1 1 i D7...D0 A7...A0 |
Operation | PC = PC + 3 IF (Ri) <> immediate data PC = PC + relative address IF (Ri) < immediate data C = 1 ELSE C = 0 |
Flags Affected | C AC F0 RS1 RS0 OV P |
Example | CJNE @R1, #24H, LABEL |
Bytes: Number of bytes required to encode the instruction. Cycles: Number of instruction cycles required to execute the instruction. Note that there are 12 oscillator cycles to one instruction cycle on a standard 8051. Encoding: Lists the byte encoding for the instruction. Operation: Lists, step-by-step, the operations performed by the instruction. Flags Affected: are highlighted in Bold |
Related topics:
8051 Program Branching Instructions | 8051 ACALL Instruction | 8051 LCALL Instruction | 8051 RET Instruction | 8051 RETI Instruction | 8051 JMP Instruction | 8051 AJMP Instruction | 8051 LJMP Instruction | 8051 SJMP Instruction | 8051 JZ Instruction | 8051 JNZ Instruction | 8051 DJNZ Instruction | 8051 NOP Instruction
List of topics: 8051
No comments:
Post a Comment