Cst207note 23
Cst207note 23
ROY POLYTECHNIC
Durgapur-713206
Program name : Computer Science and Technology
• Instruction format
Learning Outcomes:
Students will be able to:
1
Note:
1 Prerequisite
1. Program: Program is a sequence of
2 Instruction Formats
In computer organization, instruction formats refer to the binary format in which instructions
are encoded to represented in machine language. The bits of the instructions are divided into
groups called fields. The most common fields in instruction format are:
1. Opcode(Operation Code): An opcode field (in binary) specifies the operation to be per-
formed such as add, subtract, multiply, shift, complement etc.
2. Address: An address field specifies a memory address or processor register, where operand
is stored.
3. Mode: A mode field specifies the way the operand or the effective address of the operand
is determined (or located).
• Computers may have instructions of several different lengths containing varying number
of addresses (address field may be 3,2,1 or 0).
• The number of address field in the instruction format of a computer depends on the
internal organization of its registers.
There are several types of instruction formats, including zero, one, two, and three-address
instructions.
Each type of instruction format has its own advantages and disadvantages in terms of code size,
execution time, and flexibility. Modern computer architectures typically use a combination of
these formats to provide a balance between simplicity and power.
2
3 Classification of instruction based on CPU organiza-
tion
1. Single Accumulator organization
This organization was used in 1st generation computers due to the high cost of registers.
Examples are, Intel 8008, Intel 4004, intel 8085, IBM 701, ENIAC, 8051 microcontroller.
3. Stack organization
• The operands are put into stack and operations are caried out on top of stack (ToS).
The operands are implicitly specified on ToS.
• It does not use and address field for the instructions like ADD, MUL, etc (i.e Zero
address instruction format)
• PUSH and POP instructions are used to communicate with stack which require an
address field
4 Types of Instructions
Based on the number of addresses present in the instruction, instructions are classified as:
PUSH A
PUSH B
ADD
POP C
3
4.2 One Address Instructions
These instructions specify one operand or address, which typically refers to a memory location
or register. The instruction operates on the contents of that operand, and the result may be
stored in the same or a different location. For example, a one-address instruction might load
the contents of a memory location into a register.
This uses an implied ACCUMULATOR register for data manipulation. One operand is in
the accumulator and the other is in the register or memory location. Implied means that the
CPU already knows that one operand is in the accumulator so there is no need to specify it.
Example of One address instruction:
4
2. Reduced Instruction Set: It reduces the complexity of the CPU design by streamlining
the instruction set, which may boost reliability.
3. Less Decoding Complexity: Especially helpful for recursive or nested processes, which are
frequently used in function calls and mathematical computations.
4. Efficient in Nested Operations: Less bits are required to specify operands, which simplifies
the logic involved in decoding instructions.
5. Compiler Optimization: Because stacks are based on stacks, several algorithms can take
use of this to improve the order of operations.
3. Implicit Accumulator: O ften makes use of an implicit accumulator register, which can
expedite up some operations’ execution and simplify designs in other situations.
4. Code Density: S maller code in comparison to two- and three-address instructions, which
may result in more efficient use of memory and the instruction cache.
5. Efficient Use of Addressing Modes: Can make use of different addressing modes (such
indexed, direct, and indirect) to improve flexibility without adding a lot of complexity.
2. Flexible Operand Use: Increases programming variety by offering more options for operand
selection and addressing modes.
3. Intermediate Data Storage: May directly store interim results, increasing some algo-
rithms’ and calculations’ efficiency.
4. Enhanced Code Readability: Produces code that is frequently easier to read and compre-
hend than one-address instructions, which is beneficial for maintenance and troubleshoot-
ing.
5. Better Performance: Better overall performance can result from these instructions because
they minimize the amount of memory accesses required for certain processes.
2. Parallelism: Allows for the simultaneous fetching and processing of several operands,
which facilitates parallelism in CPU architecture.
5
3. Compiler Optimization: Makes it possible for more complex compiler optimizations to be
implemented, which improve execution efficiency by scheduling and reordering instruc-
tions.
4. Reduced Instruction Count: May increase execution performance even with bigger in-
struction sizes by perhaps lowering the overall number of instructions required for com-
plicated processes.
5. Improved Pipeline Utilization: More information in each instruction allows CPU pipelines
to be used more efficiently, increasing throughput overall.
6. Better Register Allocation: Permits direct manipulation of several registers inside a single
instruction, enabling more effective usage of registers.
3. Limited Addressing Capability: The processing of intricate data structures may become
more difficult since they do not directly support accessing memory regions or registers.
2. Increased Instruction Count: Multiple instructions may be needed for complex processes,
which would increase the overall number of instructions and code size.
3. Less Efficient Operand Access: There is just one operand that is specifically addressed,
which might result in inefficient access patterns and extra data management instructions.
4. Complex Addressing Modes: The instruction set and decoding procedure get more com-
plicated when several addressing modes are supported.
5. Data Movement Overhead: Moving data between memory and the accumulator could
need more instructions, which would increase overhead.
6
6.3 Disadvantages of two address instruction
1. Operand Overwriting: Usually, the result overwrites one of the source operands, which
might lead to an increase in the number of instructions needed to maintain data.
2. Larger Instruction Size: Because two-address instructions are bigger than zero- and one-
address instructions, the memory footprint may be increased.
4. Decoding Complexity: The design and performance of the CPU may be impacted by the
greater complexity involved in decoding two addresses.
5. Inefficient for Some Operations: The two-address style could still be inefficient for some
tasks, needing more instructions to get the desired outcome.
2. Complex Instruction Decoding: Three addresses to decode adds complexity to the CPU
architecture, which might affect power consumption and performance.
3. Increased Operand Fetch Time: Each instruction may execute more slowly if obtaining
three operands takes a long period.
4. Higher Hardware Requirements: Has the potential to raise cost and power consumption
since it requires more advanced hardware to handle the higher operand handling and
addressing capabilities.
5. Power Consumption: Higher power consumption is a crucial factor for devices that run on
batteries since it can be caused by more complicated instructions and increased memory
utilization.
7
Question and Answers
X=(A+B)*(C+D)
A: First we need to perform the Reverse Polish Notation for the expression, which is given by:
X=AB+CD+*
Instruction:
PUSH A
PUSH B
ADD
PUSH C
PUSH D
ADD
MUL
POP X
LOAD A ; AC ← m[A]
ADD B ; AC ← AC+M[B]
STORE T ; M[T] ← AC
LOAD C ; AC ← M[C]
ADD D ; AC ← AC + M[D]
MUL T ; AC ← AC + M[T]
STORE X ; M[X]←AC