Wednesday, March 23, 2016

8051 Jump if Bit is Set and Clear Bit

Jump if Bit is set and Clear bit

JBC bit address, relative address
If the indicated bit is one, JBC branches to the address indicated; otherwise, it proceeds with the next instruction. The bit will not be cleared if it is already a zero. The branch destination is computed by adding the signed relative-displacement in the third instruction byte to the PC, after incrementing the PC to the first byte of the next instruction. No flags are affected.

Note: When this instruction is used to test an output pin, the value used as the original data will be read from the output data latch, not the input pin.

Encoding: 0 0 0 1 0 0 0 0 bit address rel. address

The Accumulator holds 56H (01010110B). The following instruction sequence,

JBC ACC.3,LABEL1
JBC ACC.2,LABEL2

causes program execution to continue at the instruction identified by the label LABEL2, with the Accumulator modified to 52H (01010010B).

Note: All conditional jumps are short jumps (8-bit relative address). The relative address range of 00 – FFH is divided into forward and backward jumps; that is, within -128 to +127 bytes of memory relative to the address of the current PC (program counter). If the jump is forward, the target address can be within a space of 127 bytes from the current PC. If the target address is backward, the target address can be within -128 bytes from the current PC.

Example:
ORG 0H
MAIN :
MOV A, #0 ; Clear accumulator
MOV A, #10H
ADD A, P0
JBC P0.1, LABEL1
JBC ACC.2, LABEL2
ADD A, #5H
LABEL1 : SUBB A, #4H
AJMP MAIN
LABEL2 : SUBB A, #2H
AJMP MAIN
END



Related topics:
8051 Unconditional and Conditional Jump   |   8051 Long Jump   |   8051 Absolute Jump   |   8051 Short Jump   |   8051 Indirect Jump   |   8051 Jump if Accumulator Zero   |   8051 Jump if Accumulator Not Zero   |   8051 Compare and Jump if Not Equal   |   8051 Decrement and Jump if Not Zero   |   8051 Jump if Carry is Set   |   8051 Jump if Carry is Not Set   |   8051 Jump if Bit Set   |   8051 Jump if Bit Not Set

List of topics: 8051

No comments:

Post a Comment