Program Branching Operations
- A, Acc: Accumulator
- B: B special function register
- C: Carry flag in PSW
- Rn: Register R7-R0 of the currently selected Register Bank.
- dir: 8-bit internal data location’s address. This could be an Internal Data RAM location (0-127) or a SFR [i.e., I/O port, control register, status register, etc. (128-255)]. Direct Addressing Mode.
- @Ri : 8-bit internal data RAM location (0-255) addressed indirectly through register R1or R0. Indirect Addressing Mode.
- #data: 8-bit constant included in instruction. Immediate Addressing Mode.
- #data 16: 16-bit constant included in instruction. Immediate Addressing Mode.
- addr 16: 16-bit destination address. Used by LCALL and LJMP. A branch can be anywhere within the 64K byte Program Memory address space. Long Addressing Mode.
- addr 11: 11-bit destination address. Used by ACALL and AJMP. The branch will be within the same 2K byte page of program memory as the first byte of the following instruction. Absolute Addressing Mode.
- rel: Signed (two’s complement) 8-bit offset byte. Used by SJMP and all conditional jumps. Range is -128 to +127 bytes relative to first byte of the following instruction. Relative Addressing Mode.
- bit: Direct Addressed bit in Internal Data RAM or Special Function Register 1B: 1 byte
2B: 2 byte
3B: 3 byte
1C: 1 cycle
2C: 2 cycles
4C: 4 cycles
P: oscillator Period
Mnemonic | Description | |
---|---|---|
ACALL | addr11 | Absolute Subroutine Call [2B,2C,24P] |
LCALL | addr16 | Long Subroutine Call [3B,2C,24P] |
RET | Return from Subroutine [1B,2C,24P] | |
RETI | Return from interrupt [1B,2C,24P] | |
AJMP | addr11 | Absolute Jump [2B,2C,24P] |
LJMP | addr16 | Long Jump [3B,2C,24P] |
SJMP | rel | Short Jump (relative addr) [2B,2C,24P] |
JMP | @A+DPTR | Jump indirect relative to the DPTR [1B,2C,24P] |
JZ | rel | Jump if Accumulator is Zero [2B,2C,24P] |
JNZ | rel | Jump if Accumulator is Not Zero [2B,2C,24P] |
CJNE | A,direct,rel | Compare direct byte to Acc and Jump if Not Equal [3B,2C,24P] |
CJNE | A,#data,rel | Compare immediate to Acc and Jump if Not Equal [3B,2C,24P] |
CJNE | Rn,#data,rel | Compare immediate to register and Jump if Not Equal [3B,2C,24P] |
CJNE | @Ri,#data,rel | Compare immediate to indirect and Jump if Not Equal [3B,2C,24P] |
DJNZ | Rn,rel | Decrement register and Jump if Not Zero [2B,2C,24P] |
DJNZ | direct,rel | Decrement direct byte and Jump if Not Zero [3B,2C,24P] |
NOP | No operation [1B,1C,12P] |
Jump
LJMP (long jump) causes the program to branch to a destination address defined by the 16-bit operand in the jump instruction. Because a 16-bit address is used the instruction can cause a jump to any location within the 64KByte program space (216 = 64K).
LJMP LABEL_X ; Jump to the specified label
LJMP 0F200h ; Jump to address 0F200h
LJMP @A+DPTR ; Jump to address which is the sum of DPTR and Reg. A
SJMP (short jump) uses a singe byte address. This address is a signed 8-bit number and allows the program to branch to a distance –128 bytes back from the current PC address or +127 bytes forward from the current PC address.
AJMP allows a jump with a 2KByte address boundary (a 2K page)
Most 8051 jump instructions use an 8-bit destination address, based on relative addressing, i.e. addressing within the range –128 to +127 bytes.
JZ LABEL_1 ; Jump to LABEL_1 if accumulator is equal to zero
JNZ LABEL_X ; Jump to LABEL_X if accumulator is not equal to zero
JNC LABEL_Y ; Jump to LABEL_Y if the carry flag is not set
DJNZ R2, LABEL ; Decrement R2 and jump to LABEL if the resulting value of R2 is not zero.
CJNE R1, #55h , LABEL_2 ; Compare the magnitude of R1 and the number 55h and jump to LABEL_2 if the magnitudes are not equal.
Call
LCALL instruction is used to call a subroutine at a specified address. The address is 16 bits long so the call can be made to any location within the 64KByte memory space.
ACALL instruction is logically similar to the LCALL but has a limited address range similar to the AJMP instruction.
Return
The return from subroutine is achieved using the RET instruction.
Related topics:
8051 Instruction Set Overview | 8051 Instruction Cycle | 8051 Machine Cycle | 8051 Instruction Set Summary | 8051 Arithmetic Operation Instructions | 8051 Logical Operation Instructions | 8051 Data Transfer Instructions | 8051 Boolean Variable Manipulation Instructions | 8051 Instruction Opcode | 8051 Instructions that Affect Flag Settings | 8051 Instructions and Examples
List of topics: 8051
No comments:
Post a Comment