CompArch05 Handout 1
CompArch05 Handout 1
Procedural and Loop Instructions o The content of the instruction pointer (IP) is then changed with the
Procedural Calls address of the first instruction of the procedure.
Procedures are considered the most important innovation in the development o The subsequent instructions of the procedure are stored in the
of programming languages. A procedure is a self-contained computer program instruction queue for execution
that is incorporated into a large program. At any point in the program, the
procedure may be invoked or called. The processor is instructed to execute A Near CALL is an instruction to call a procedure that is in the same code
the entire procedure and then return to the point from which the call took place. segment as the CALL instruction that calls it, while the Far CALL is used
Procedures are also known as subroutines. Below are some characteristics to call a procedure from a different segment.
of a procedure (Stallings, 2019):
• It allows the same piece of code to be used multiple times. Common x86 call instructions:
• It improves efficient use of storage space in a system. Instruction Description
• It allows large programming tasks to be subdivided into smaller units. CALL Address This instruction pushes the current IP value onto the stack and
causes a jump to the entry point of the procedure by placing
• It greatly eases the programming tasks.
the address of the entry point in the IP. This basically calls a
• It can be called from more than one (1) location. procedure of a function.
• A procedure call can appear in another procedure, which allows the CALL Label This instruction pushes the content of the IP onto the stack
nesting procedures to an arbitrary depth. (Near) and jumps to the offset address in the current code segment.
• All procedure call is matched by a return instruction in the called program. CALL Label This instruction pushes the content of the IP onto the stack
(Far) and jumps to the offset address in any memory location.
In order to call a procedure from a variety of points, the processor must save CALL Memory This instruction pushes the content of the IP onto the stack
the return address so that the return process can take place correctly. The (Near) and jumps to the offset address in the memory register of the
return address can be stored in a register, start of the called procedure, or at current code segment.
CALL Memory This instruction pushes the content of the IP onto the stack
the top of the stack.
(Far) and jumps to the offset address of the register at any memory
location.
A reentrant procedure is a procedure that can be implemented in such a way
that more than one process can execute it at the same time without any 2. Return instruction (RET): This returns the control to the place from which
conflict. Storing the return address in a register or at the start of the called a procedure was called. Thus, it is the last instruction in any procedure.
procedure complicates the utilization of the reentrant procedure. If the The following activities take place inside the microprocessor when the
parameters are passed via register or memory for a reentrant procedure, a RET instruction is used (Sharma, 2019):
specific set of codes must be responsible for saving the parameters so that o The address of the next instruction in the mainline program, which was
the register or memory space is available for other procedural calls (Stallings, previously stored inside the stack, is fetched again and is placed inside
2019). the instruction pointer (IP).
o The instruction queue will again be filled with the subsequent
The procedure mechanism involves two (2) basic instructions, which are: instructions of the mainline program.
1. Call instruction (CALL): This branches from the present location to the
procedure. The following activities take place inside the microprocessor Emu8086 return instructions:
when the CALL instruction is used (Sharma, 2019): Instruction Description
o The address of the next instruction that exists in the program is stored RET This instruction returns the address from a near procedure. The
in the stack. return will be done by replacing the instruction pointer (IP) with a
o The instruction queue is emptied to accommodate the instructions of word from the top of the stack. Possible algorithms:
the procedure. Pop from stack: IP