Jump and Call Instructions
There are 3 types of jump instructions. They are:-
  1. Relative Jump
  2. Short Absolute Jump
  3. Long Absolute Jump
Relative Jump

Jump that replaces the PC (program counter) content with a new address that is greater than (the address following the jump instruction by 127 or less) or less than (the address following the jump by 128 or less) is called a relative jump. Schematically, the relative jump can be shown as follows:

Fig 1. Relative Jump

The advantages of the relative jump are as follows:
  1. Only 1 byte of jump address needs to be specified in the 2's complement form, ie. For jumping ahead, the range is 0 to 127 and for jumping back, the range is -1 to -128.
  2. Specifying only one byte reduces the size of the instruction and speeds up program execution.
  3. The program with relative jumps can be relocated without reassembling to generate absolute jump addresses.
Disadvantages of the absolute jump:
  1. Short jump range (-128 to 127 from the instruction following the jump instruction)

Instructions that use Relative Jump
SJMP <relative address> 

(The remaining relative jumps are conditional jumps)
JC <relative address> 
JNC <relative address>
JB bit, <relative address>
JNB bit, <relative address>
JBC bit, <relative address>
CJNE <destination byte>, <source byte>, <relative address>
DJNZ <byte>, <relative address>
JZ <relative address>
JNZ <relative address>

Short Absolute Jump

In this case only 11bits of the absolute jump address are needed. The absolute jump address is calculated in the following manner. 
In 8051, 64 kbyte of program memory space is divided into 32 pages of 2 kbyte each. The hexadecimal addresses of the pages are given as follows:

Page (Hex)
Address (Hex)
00
0000 - 07FF
01
0800 - 0FFF
02
1000 - 17FF
03
1800 - 1FFF
.
.
1E
F000 - F7FF
1F
F800 - FFFF

It can be seen that the upper 5bits of the program counter(PC) hold the page number and the lower 11bits of the PC hold the address within that page. Thus, an absolute address is formed by taking page numbers of the instruction (from the program counter) following the jump and attaching the specified 11bits to it to form the 16-bit address.

Advantage: The instruction length becomes 2 bytes.

However, difficulty is encountered when the next instruction following the jump instruction begins from a fresh page (at X000H or at X800H). This does not give any problem for the forward jump, but results in an error for the backward jump. In such a case the assembler prompts the user to relocate the program suitably.
Example of short absolute jump:
ACALL <address 11> 
AJMP   <address 11>

Long Absolute Jump/Call

Applications that need to access the entire program memory from 0000H to FFFFH use long absolute jump. Since the absolute address has to be specified in the op-code, the instruction length is 3 bytes (except for JMP @ A+DPTR). This jump is not re-locatable.

Example:
LCALL <address 16> 
LJMP    <address 16>
JMP @A+DPTR

Post a Comment

 
Top