Jump instructions in 8051

Normally the processor executes the program in a sequential manner, due to continuous increment of PC ( program counter ). Jump instructions in 8051 that jumps to another part of the program by violating sequential execution.

Eg: ‘for’ loop in other programming languages.
goto instruction in c language

Similarly jump instruction is used in 8051 microcontrollers. There are three types of jump instruction in 8051

  • LJMP
  • SJMP
  • AJMP

LJMP ( Long Jump ):

Syntax: LJMP address
The program execution directly jumps to the specified address. This instruction can be used for 64Kb of memory. It has a range of 65,536 addresses, and can jump over these many addresses. So named Long jump. 

This instruction consumes 3 bytes of instruction( size of instruction ).

LJMP – 1 byte 
Address – it is a 16-bit address , so 2 bytes.
When a particular address is given in the instruction that address is stored in the PC.

long jump instruction in 8051
long jump instruction in 8051

There is a problem with this jump instruction

  • It consumes 3 bytes of instruction, meaning 3 cycles ( 8051 can fetch 8-bit once ) which consumes more time.
  • We never use 65,536 sized jumps, we never write a for loop that consists 65K+ program lines. 

SJMP ( Small Jump ):

syntax: SJMP Raddress;
Here Raddress stands for relative address. Instead of giving address locations to the instruction , we give difference between the addresses ( not actually the difference ). Here the address consumes 1 byte which means only 256 address jumps can be fetched. But jump operation is not done always ahead, even behind too, So we have to use signed numbers, so the range is -128 to 127. It means we can use jump only for ahead or behind 128 jumps. If our present PC = 1128H , we can jump between 1000H and 1250H. 

Let us consider PC=1128H, and our target is 1131H ( difference between target address and present address is relative address=9 )

SJMP radd; This instruction is stored in 1128H and 1129H, because it is a 2byte address, so we need 2 address locations. Once content of a location is fetched, the PC gets incremented, so after 2 contents are fetched 8051 gives the address to the PC.

Short jump instruction in 8051
Short jump instruction in 8051

Step 1: SJMP is stored in 1128H location.

Step 2: relative address ( 7H ) is stored in the next location ( 1129H ).

Step 3: After fetching 1129H location PC gets incremented and has 112A in it.

Step 4: Now PC gets added with the relative address.

Step 5: Jump is successful.

This jump is a widely used one. But this jump instruction has comparatively low range.

AJMP ( Absolute Jump ):

syntax: AJMP address;
In this type of jump instruction , the whole 64Kb memory is divided into 32 parts ( each part is known as page ) each consisting of 2KB of memory. Each page consists of 2048 locations. Absolute jump is performed inside a page only. This instruction is of 2 bytes.

1 byte for AJMP data type
1 byte for address ( 8 bit address is given )

Ajump instruction in 8051
Ajump instruction in 8051

In decimal form, each location has a 16-bit address. For any Page upper 5 bits remains  Same throughout the page. So in absolute jump, the upper 5 bits can be removed. 

Every location in a page has 16 bits of address. Out of which

  • Lower 8 bits are decided by 1 byte address given in the AJMP instruction.
  • Higher 5 bits are common in any page.
  • Remaining 3 bits has 8 options ( 23 = 8 ).

These remaining 3 bits have different 8 opcodes. 

AJMP 12H;

First AJMP decides 1 of 8 opcodes based on user instructions.
While programming the 8051, the programmer never knows the address of the location. So we use labels instead of address. 

Read other topics:
Branch operations in 8086
read about conditional and non conditional jumps>>>>

Spread knowledge

Leave a Comment

Your email address will not be published.