Thursday, March 7, 2019

FMA Unit 2.5 Jump and Call Instructions


Data Pointer:
The Data Pointer (DPTR) is the 8051'sonly user-accessible 16-bit (2-byte) register. It is used by the 8051 to access external memory using the address indicated by DPTR. DPTR is the only 16-bit register available and is often used to store 2-byte values.
Program Counter:
The Program Counter (PC) is a 2-byte address which tells the 8051 where the next instruction to execute is found in memory. When the 8051 is initialized PC always starts at 0000h and is incremented each time an instruction is executed.
Interrupt:
An interrupt is a signal to the processor emitted by hardware or software indicating an event that needs immediate attention. Whenever an interrupt occurs, the controller completes the execution of the current instruction and starts the execution of an Interrupt Service Routine (ISR).
ISR tells the processor or controller what to do when the interrupt occurs. The interrupts can be either hardware interrupts or software interrupts.

Subroutines:
Subroutines are the set of instructions that will written separately from main program regarding a task that occur at main program frequently

Program and Machine Control Instruction
       A.   LOOP:
Repeating a sequence of instructions a certain number of times is called a loop
     
    B.   CALL:

      1.     ACALL
Absolute Call Within 2K Block
Syntax:
ACALL code address
Bytes:
2


Description: ACALL unconditionally calls a subroutine at the indicated code address. ACALL pushes the address of the instruction that follows ACALL onto the stack, least-significant-byte first, most-significant-byte second. The Program Counter is then updated so that program execution continues at the indicated address.
The new value for the Program Counter is calculated by replacing the least-significant-byte of the Program Counter with the second byte of the ACALL instruction, and replacing bits 0-2 of the most-significant-byte of the Program Counter with 3 bits that indicate the page. Bits 3-7 of the most-significant-byte of the Program Counter remain unchanged.
Since only 11 bits of the Program Counter are affected by ACALL, calls may only be made to routines located within the same 2k block as the first byte that follows ACALL

      2.     LCALL Instruction:
Long Call
Syntax:
LCALL code addr
Byte:
3


Description: LCALL calls a program subroutine. LCALL increments the program counter by 3 (to point to the instruction following LCALL) and pushes that value onto the stack (low byte first, high byte second). The Program Counter is then set to the 16-bit value which follows the LCALL opcode, causing program execution to continue at that address.
   
     C.   RETURN

      1.     RET
Function:
Return From Subroutine
Syntax:
RET
Byte:
1
Description: RET is used to return from a subroutine previously called by LCALL or ACALL. Program execution continues at the address that is calculated by popping the topmost 2 bytes off the stack. The most-significant-byte is popped off the stack first, followed by the least-significant-byte.

     2.     RETI Instruction: (Return from Interrupt)
Function:
Return From Interrupt
Syntax:
RETI
Byte:
1
Description: RETI is used to return from an interrupt service routine. RETI first enables interrupts of equal and lower priorities to the interrupt that is terminating. Program execution continues at the address that is calculated by popping the topmost 2 bytes off the stack. The most-significant-byte is popped off the stack first, followed by the least-significant-byte.
RETI functions identically to RET if it is executed outside of an interrupt service routine.

     D.   JUMP (unconditionally jumps)
     1.     AJMP
Absolute Jump Within 2K Block
Syntax:
AJMP code address
Byte:
2

Description: AJMP unconditionally jumps to the indicated code address. The new value for the Program Counter is calculated by replacing the least-significant-byte of the Program Counter with the second byte of the AJMP instruction, and replacing bits 0-2 of the most-significant-byte of the Program Counter with 3 bits that indicate the page of the byte following the AJMP instruction. Bits 3-7 of the most-significant-byte of the Program Counter remain unchanged.
Since only 11 bits of the Program Counter are affected by AJMP, jumps may only be made to code located within the same 2k block as the first byte that follows AJMP.

      2.     LJMP
Long Jump
Syntax:
LJMP code addr
Byte:
3

Description: LJMP jumps unconditionally to the specified code addr.


    3.     SJMP
Function:
Short Jump
Syntax:
SJMP reladdr
Bytes
2

Description: SJMP jumps unconditionally to the address specified reladdrReladdr must be within -128 or +127 bytes of the instruction that follows the SJMP instruction.


      E.   JUMP (conditionally jumps)

   1.     JB
Jump if Bit Set
Syntax:
JB bit addrreladdr
Byte:
3

Description: JB branches to the address indicated by reladdr if the bit indicated by bit addr is set. If the bit is not set program execution continues with the instruction following the JB instruction.

   2.     JNB
Function:
Jump if Bit Not Set
Syntax:
JNB bit addr, reladdr
Byte:
3

Description: JNB will branch to the address indicated by reladdress if the indicated bit is not set. If the bit is set program execution continues with the instruction following the JNB instruction.
    
   3.      JBC
JBC
Function:
Jump if Bit Set and Clear Bit
Syntax:
JB bit addrreladdr
Byte:
3

Description: JBC will branch to the address indicated by reladdr if the bit indicated by bit addr is set. Before branching to reladdr the instruction will clear the indicated bit. If the bit is not set program execution continues with the instruction following the JBC instruction.
   
   4.      JC
Jump if Carry Set
Syntax:
JC reladdr
Byte:
2

Description: JC will branch to the address indicated by reladdr if the Carry Bit is set. If the Carry Bit is not set program execution continues with the instruction following the JC instruction.
   
   5.      JNC
Jump if Carry Not Set
Syntax:
JNC reladdr
Byte:
2

Description: JNC branches to the address indicated by reladdr if the carry bit is not set. If the carry bit is set program execution continues with the instruction following the JNB instruction.
   
   6.      JMP
Jump to Data Pointer + Accumulator
Syntax:
JMP @A+DPTR
Byte:
1

Description: JMP jumps unconditionally to the address represented by the sum of the value of DPTR and the value of the Accumulator.

  7.     JZ
Jump if Accumulator Zero
Syntax:
JZ reladdr
Bytes:
2

Description: JZ branches to the address indicated by reladdr if the Accumulator contains the value 0. If the value of the Accumulator is non-zero program execution continues with the instruction following the JNZ instruction.

Jump if Accumulator Not Zero
Syntax:
JNZ reladdr
Byte:
2

Description: JNZ will branch to the address indicated by reladdr if the Accumulator contains any value except 0. If the value of the Accumulator is zero program execution continues with the instruction following the JNZ instruction.
  
  9.      SJMP
Short Jump
Syntax:
SJMP reladdr
Bytes
2

Description: SJMP jumps unconditionally to the address specified reladdrReladdr must be within -128 or +127 bytes of the instruction that follows the SJMP instruction.
  
  10.                        CJNE
Compare and Jump If Not Equal
Syntax:
CJNE operand1,operand2,reladdr
Bytes:
3

Description: CJNE compares the value of operand1 and operand2 and branches to the indicated relative address if operand1 and operand2 are not equal. If the two operands are equal program flow continues with the instruction following the CJNE instruction.
The Carry bit (C) is set if operand1 is less than operand2, otherwise it is cleared.

  11.                        DCJNZ
Decrement and Jump if Not Zero
Syntax:
DJNZ register,reladdr
Byres:
3

Description: DJNZ decrements the value of register by 1. If the initial value of register is 0, decrementing the value will cause it to reset to 255 (0xFF Hex). If the new value of register is not 0 the program will branch to the address indicated by relative addr. If the new value of register is 0 program flow continues with the instruction following the DJNZ instruction.

  12.                        NOP
None, waste time
Syntax:
No Operation
Byte:
1

Description: NOP, as it's name suggests, causes No Operation to take place for one machine cycle. NOP is generally used only for timing purposes. Absolutely no flags or registers are affected.

No comments:

Post a Comment