[go: up one dir, main page]

0% found this document useful (0 votes)
19 views3 pages

CompArch05 Handout 1

The document discusses procedural and loop instructions in programming, highlighting the significance of procedures as self-contained programs that can be invoked multiple times. It explains the mechanics of CALL and RET instructions for procedure calls and returns, as well as various types of jump and branch instructions that control program flow. Additionally, it covers iteration and looping instructions, emphasizing their role in executing repetitive tasks until specific conditions are met.

Uploaded by

venanciojenny08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
19 views3 pages

CompArch05 Handout 1

The document discusses procedural and loop instructions in programming, highlighting the significance of procedures as self-contained programs that can be invoked multiple times. It explains the mechanics of CALL and RET instructions for procedure calls and returns, as well as various types of jump and branch instructions that control program flow. Additionally, it covers iteration and looping instructions, emphasizing their role in executing repetitive tasks until specific conditions are met.

Uploaded by

venanciojenny08
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

IT2104

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

05 Handout 1 *Property of STI


 student.feedback@sti.edu Page 1 of 3
IT2104
 If immediate operand is present: SP = SP + operand Jump Instructions
RETF This instruction returns the address from a far procedure. The return Jump instructions facilitate the transfer of the program sequence to the
will be done by replacing the stack pointer (SP) with a word at the memory address given in the operand, based on the specified flag. These
top of the stack. Possible algorithms: instructions are technically used for changing the execution flow of instructions
 Pop from stack: IP or CS
in the processor by jumping to any instruction in between the code. Jump
 If immediate operand is present: SP = SP + operand
instructions are divided into two types (Sharma, 2019):
• Unconditional Jump Instructions – These are used to jump on a
Branch Instructions
particular location unconditionally. Thus, there is no specific condition that
A branch instruction contains the address of the next instruction to be
needs to be satisfied for the jump to take place. There are three (3) types
executed as one of its operands (Stallings, 2019). These instructions are used
of unconditional jump:
to implement control flow in program loops and conditionals. A branch
1. Near JMP – This procedure targets memory location within the
instruction is generally classified as follows (JavaTpoint, n.d.):
same code segment (intra-segment).
• Direct: The instruction contains the target address.
2. Short JMP – This procedure targets memory location within the
• Indirect: The instruction specifies where the target address is to be found. same code segment (intra-segment), but the offset is 1byte long.
• Relative: The instruction specifies the differences between the current and 3. Far JMP – This procedure targets memory location that is outside
the target address. the segment (inter-segment), and the size of the instruction
pointer is a double word.
In computer organization, a branch may also refer to the act of switching • Conditional Jump Instructions – In implementing conditional jumps, the
execution to a different instruction sequence as a result of executing a branch processor must check for a specific condition for the jump to take place.
instruction. Note that a branch can either be forward – instructions with higher Each status flag, or a combination of the status flags, is tested for a
addresses or backward – instructions with lower addresses. A branch conditional jump. The following are the status bits of each flag and its
instruction computes the target address in one of the following ways corresponding name: C – carry flag, P – parity flag, A – auxiliary carry flag,
(JavaTpoint, n.d.): Z – zero flag, S – sign flag, and O – overflow flag.
• The target address is the sum of a constant and the address of the branch
instructions itself. Some Emu8086 jump instructions:
• The target address is the absolute address given as an operand to the Instructions Description Algorithm
instruction. JA Label Short jump if the 1st operand is above the If C=0 and Z=0, then
• The target address is the address found in the link register. 2nd operand (as set by the CMP jump.
• The target address is the address found in the count register. instruction); Unsigned
JAE Label Short jump if the 1st operand is above or If C=0, then jump.
Below are the two (2) categories of branch instructions: equal to the 2nd operand (as set by the
1. Unconditional branches – These instructions always result in branching. CMP instruction); Unsigned
JB Label Short jump if 1st operand is below the 2nd If C=1, then jump.
2. Conditional branches – These branch instructions may or may not cause
operand (as set by the CMP instruction);
branching, depending on some specified conditions. The address of the Unsigned
next instruction following a conditional branch instruction cannot be JBE Label Short jump if 1st operand is below or equal If C=1 or Z=1, then
confirmed until the branch condition has been evaluated (Ledin, 2020). to the 2nd operand (as set by CMP jump.
o If the branch condition is not satisfied, the processor will execute the instruction); Unsigned
instruction that follows the conditional branch. JC Label Short jump if carry flag is set to 1 If C=1, then jump.
o If the branch condition is satisfied, the next instruction is at the address
indicated in the conditional branch instruction.

05 Handout 1 *Property of STI


 student.feedback@sti.edu Page 2 of 3
IT2104
JE Label Short jump if 1st operand is equal to 2nd If Z=1, then jump. the value of Z is one o jump
operand (as set by the CMP instruction); (equal) else
Either signed or unsigned o no jump, continue
JG Label Short jump if 1st operand is greater than If Z=0 and S=F, then LOOPNE/LOOPNZ Decrease the CX; Jump to • CX=CX-1
the 2nd operand (as set by the CMP jump. Label label if CX is not zero and • If CX<>0 and Z=0 then,
instruction); Signed the value of Z is zero (not o jump
JMP Label Unconditional jump; Transfers control to Always jump equal) else
another part of the program; 4byte o no jump, continue
address may be entered in the form: JCXZ Label Short jump if CX register If CX=0, then jump.
1234h:5678h, where the 1st value is a is 0
segment and the 2nd value is an offset
JNP Label Short jump if no parity (odd); Only the 8 If P=0, then jump. Programs typically contains a number of iterative loops and subroutines. Once
low bits of the result are checked; Set by a loop or a subroutine is entered, there are repeated referencing to a small set
the CMP, SUB, ADD, TEST, AND, OR, or
of instructions.
XOR instructions
JP Label Short jump if parity (even); Only the 8 low If P=1, then jump.
References:
bits of the result are checked; Set by the JavaTpoint (n.d.). Branch instruction in computer organization. Retrieved on November 4, 2021 from https://www.javatpoint.com/branch-
CMP, SUB, ADD, TEST, AND, OR, or instruction-in-computer-organization
Ledin, J. (2020). Modern computer architecture and organization. Packt Publishing
XOR instructions Naeem, A. (n.d.). What are loops in assembly language?. Retrieved on November 6, 2021 from https://www.educative.io/edpresso/what-
JNS Label Short jump if not signed (if positive); Set If S=0, then jump. are-loops-in-assembly-language
by CMP, SUB, ADD, TEST, AND, OR, or Sharma, M. (2019, July 26). Jump instructions in 8086 microprocessor. Retrieved on November 5, 2021 from
https://www.includehelp.com/embedded-system/jump-instructions-in-8086-microprocessor.aspx
XOR instructions. Sharma, M. (2019, July 30). The CALL and RET instruction in the 8086 microprocessor. Retrieved on November 4, 2021 from
JS Label Short jump is signed (if negative); Set by If S=1, then jump. https://www.includehelp.com/embedded-system/the-call-and-ret-instruction-in-the-8086-microprocessor.aspx
Stallings, W. (2019). Computer organization and architecture: Designing for performance (11th ed.). Pearson Education, Inc.
CMP, SUB, ADD, TEST, AND, OR, or
XOR instructions.
JO Label Short jump if overflow If O=1, then jump.

Iterations and Looping


A loop is a block of statements that are repeatedly executed until a specific
condition is satisfied. In assembly language, the JMP instruction is commonly
used to implement loops. However, the processor instruction set includes a
group of loop instructions for implementing iterations conveniently (Naeem,
n.d.).

Common x86 iteration and looping instructions:


Instruction Description Algorithm
LOOP Label Decreases the CX; Jump • CX=CX-1
to label if CX is not zero • If CX<>0 then
o jump
else
o no jump, continue
LOOPE/LOOPZ Decrease the CX; Jump to • CX=CX-1
Label label if CX is not zero and • If CX<>0 and Z=1 then

05 Handout 1 *Property of STI


 student.feedback@sti.edu Page 3 of 3

You might also like