CALL addr:
- The CALL instruction is used to transfer the program control to a subprogram or subroutine.
NOTE: A subroutine is a group of instructions which performs a particular task and is executed a number of times. Rather than writing this repeated part again and again, the programmer writes this part only once. It is written separately. The processor executes this part by transferring program control from main program to the subroutine program. After completion of execution of subroutine, the program control is back to the main program.
Subroutine Program |
- The CALL instruction transfers the program control to the address given in the instruction.
- The current contents of program counter (PC) are copied into the stack.
NOTE: Stack is a part of read/write memory which is used for storing temporary results and addresses.
- Then this instruction decrements stack pointer (SP) by two.
- No flags are affected.
- It is a three byte instruction.
- Immediate addressing mode is used.
Example:
If SP = 2000H, then
6000H CALL 1000H ; This instruction will store the address of the instruction next to CALL i.e. 6003H on the stack and load program counter with 1000H.
Before execution:
After execution:
Before execution:
After execution:
Ccond addr:
- When the condition is true, this instruction calls the subroutine at the address given in the instruction.
- When the condition is false, this instruction executes the instruction after the CALL instruction.
- If the condition is true, the current contents of program counter are copied into the stack and stack pointer is decremented by two.
- No flags are affected. They are only checked.
- It is a three byte instruction.
- Immediate addressing mode is used.
If CY = 1 and SP = 2000H
6000H CC 1000H ; This instruction will store the address of the instruction next to CALL i.e. 6003H on the stack and load program counter with 1000H since CY = 1.
Comments
Post a Comment