The Wayback Machine - https://web.archive.org/web/20250216100113/https://www.geeksforgeeks.org/difference-call-jump-instructions/
Open In App

Difference between CALL and JUMP instructions

Last Updated : 30 Sep, 2024
Summarize
Comments
Improve
Suggest changes
Like Article
Like
Share
Report
News Follow

In assembly language as well as in low level programming CALL and JUMP are the two major control transfer instructions. Both instructions enable a program to go to different other parts of the code but both are different. CALL is mostly used to direct calls to subroutine or a function and regresses to the main program after function call only. On the other hand, JUMP cause the control to jump to another part of code and does not return. CALL and JUMP you need to understand well especially when operating at low levels and the optimizations to the control flow of a program.

What is CALL Instruction?

The CALL instruction involves in calling up a subroutine or a function used in assembly language. During CALL, the address of the instruction after the CALL instruction is stored on the stack since after a subroutine has been executed, the control flows back to the main program. This feature makes CALL suitable in areas, where a given line of code can be run several times for instance in function calls.

Advantages of CALL Instruction

  • Code Reusability: The CALL instruction is used to call subroutines thus making the codes reusable. This eliminates repetition, and has the added benefits of making the overall structure of the program easier to develop.
  • Ease of Maintenance: It is easy to alter the program because the same subroutine is used many times. Any modifications that are done in the subroutine are implemented wherever its CALL instruction is employed.
  • Program Control: CALL allows to come back to the point of the program where execution was interrupted with less interruptions, more controlled and less random program flow.

Disadvantages of CALL Instruction

  • Performance Overhead: The CALL instruction also include pushing the address of the next instruction to the stack which is not serious but may cause some performance degrade in cases where time is of high essence.
  • Stack Management: Various problems such as stack overflow or memory problems can occur because of improper stack management (wrong disposing of a call, for example).

What is JUMP Instruction?

The unconditioned branch instruction is called the JUMP or JMP for short where it is able to transfer control to a different part of the program. Like CALL, after JUMP executes the jump the program moves to the target address, the only difference is that there are no RETURN information needed to return back to the starting point. Basically, JUMP is utilized to do branching operations within the given code or to omit instructions liking certain code further.

Advantages of JUMP Instruction

  • Efficiency: This implies that JUMP instructions are usually faster than CALL instructions since the latter necessitate the saving and managing of return addresses.
  • Simpler Control Flow: For loops, conditions, and for exiting some parts of the code without coming back are best suited to be used in JUMP.
  • Lower Overhead: In this way, unlike in the case of CALL, no return address is pushed on the stack, and, therefore, JUMP has lesser overhead.

Disadvantages of JUMP Instruction

  • No Return Mechanism: There are no means to go back to the position where the JUMP instruction was executed which may prove problematic in some cases especially when one is debugging.
  • Risk of Unstructured Code: This is especially because the use of JUMP instructions in a program’s code can result in generation of what is known as spaghetti code.
SERIAL NO. JUMP CALL
1. Program control is transferred to a memory location which is in the main program Program Control is transferred to a memory location which is not a part of main program
2. Immediate Addressing Mode Immediate Addressing Mode + Register Indirect Addressing Mode
3. Initialization of SP(Stack Pointer) is not mandatory Initialization of SP(Stack Pointer) is mandatory
4. Value of Program Counter(PC) is not transferred to stack Value of Program Counter(PC) is transferred to stack
5. After JUMP, there is no return instruction After CALL, there is a return instruction
6. Value of SP does not changes Value of SP is decremented by 2
7. 10 T states are required to execute this instruction 18 T states are required to execute this instruction
8. 3 Machine cycles are required to execute this instruction 5 Machine cycles are required to execute this instruction

Conclusion

The CALL and JUMP statements are used commonly in the Assembly language to control flow of programs, though they exhibit different functionalities. CALL is used for calling subroutines with the option or privilege of the get back to the main program while JUMPs pass control unconditionally to other part without return. CALL is more rigid yet it incorporates code reuse as compared to JUMP that is highly optimized especially to work with small SCPs but lacks backtrack mechanism. Orientation in the applicative need can make the difference of using CALL and JUMP in effectivity and maintainability of the code.

Difference between CALL and JUMP instructions-FAQs

Can CALL and JUMP instructions be used interchangeably?

Unfortunately, they cannot be used for one another. CALL is used for passing control to other subroutines and then returning back while JUMP is used to pass control to another part to execute instructions without coming back again.

What happens if a subroutine called by a CALL instruction does not return?

In case a subroutine fails to return through the right channels or through an appropriate return flow (such as RET), the program flow will not return to the calling point and will thus make the program dysfunctional or lead to a crash.

 Is JUMP instruction always unconditional?

Not necessarily. There are JUMP conditional type instructions that transfers control only under some condition like compare of two registers or flag bits.

 How does CALL instruction affect the stack?

If CALL instruction is executed, then the address of the next instruction after that, is placed on the stack so that the program can come back to it after it is done with the subroutine.


Next Article

Similar Reads

three90RightbarBannerImg