User Tools

Site Tools


spo600:procedure_call

This is an old revision of the document!


Procedure Call

A procedure is a block of code that may be called by other code. Depending on the language in used, a procedure may also be called a routine, function, subroutine, method, or subprogram.

At the machine level, a procedure is called like this:

  1. A program (known as the caller) uses an instruction to invoke the procedure. This is known as “performing a call”.
    1. The current value of the program counter is saved either to a stack or to a register. This is known as the return address.
    2. The address of the entry point in the called procedure is loaded into the system's .
  2. The called procedure (known as the callee) executes zero or more instructions.
  3. The callee executes an instruction to return to the caller.
    1. The return operation is performed by loading the return address into the program counter.

The actual value of the return address saved during a procedure call may be the address of the first byte of the call instruction, the last byte of the call instruction, or the first byte of the instruction following the call instruction, depending on the architecture of the system.

Note that the return address is saved differently by various architectures:

  • Some systems store the return address into a link register. This has the advantage of avoiding access to the main memory, which is much slower than registers. However, if a called procedure needs to call another procedure, it must save the contents of the link register.
  • Other systems store the return address on the stack. This is slower but does not require additional code when performing a subsequent call.
spo600/procedure_call.1739985575.txt.gz · Last modified: 2025/02/19 17:19 by chris

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki