COA Unit 3
COA Unit 3
Note: The Operation code (Opcode) of an instruction refers to a group of bits that define
arithmetic and logic operations such as add, subtract, multiply, shift, and compliment.
Input-Output instruction
Just like the Register-reference instruction, an Input-Output instruction does not need a
reference to memory and is recognized by the operation code 111 with a 1 in the
leftmost bit of the instruction. The remaining 12 bits are used to specify the type of the
input-output operation or test performed.
Note
o The three operation code bits in positions 12 through 14 should be equal to 111.
Otherwise, the instruction is a memory-reference type, and the bit in position 15
is taken as the addressing mode I.
o When the three operation code bits are equal to 111, control unit inspects the bit
in position 15. If the bit is 0, the instruction is a register-reference type.
Otherwise, the instruction is an input-output type having bit 1 at position 15.
Arithmetic, logic and shift instructions provide computational capabilities for processing
the type of data the user may wish to employ.
A huge amount of binary information is stored in the memory unit, but all computations
are done in processor registers. Therefore, one must possess the capability of moving
information between these two units.
Program control instructions such as branch instructions are used change the sequence
in which the program is executed.
Input and Output instructions act as an interface between the computer and the user.
Programs and data must be transferred into memory, and the results of computations
must be transferred back to the user.
Instruction Formats (Zero, One, Two and
Three Address Instruction)
A computer performs a task based on the instruction provided. Instruction in
computers comprises groups called fields. These fields contain different
information as for computers everything is in 0 and 1 so each field has different
significance based on which a CPU decides what to perform. The most
common fields are:
Operation field specifies the operation to be performed like addition.
Address field which contains the location of the operand, i.e., register or
memory location.
Mode field which specifies how operand is to be founded.
Instruction is of variable length depending upon the number of addresses it
contains. Generally, CPU organization is of three types based on the number of
address fields:
1. Single Accumulator organization
2. General register organization
3. Stack organization
In the first organization, the operation is done involving a special register called
the accumulator. In second on multiple registers are used for the computation
purpose. In the third organization the work on stack basis operation due to
which it does not contain any address field. Only a single organization doesn’t
need to be applied, a blend of various organizations is mostly what we see
generally.
Based on the number of address, instructions are classified as:
Note that we will use X = (A+B)*(C+D) expression to showcase the procedure.
PUSH A TOP = A
PUSH B TOP = B
PUSH C TOP = C
PUSH D TOP = D
Expression: X = (A+B)*(C+D)
AC is accumulator
M[] is any memory location
M[T] is temporary location
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
MOV R2, C R2 = C
ADD R2, D R2 = R2 + D
MUL R1, R2 R1 = R1 * R2
MOV X, R1 M[X] = R1
Expression: X = (A+B)*(C+D)
R1, R2 are registers
M[] is any memory location
Fetch cycle: In this cycle, the processor reads the instruction that is to be
executed from the memory.
Execute cycle: In this cycle, the processor interprets the opcode of the fetched
instruction and performs the operations accordingly.
The figure below shows you the processing of the basic instruction cycle. In
the beginning, to start the execution of a program, the processor runs the
fetch cycle and fetches the first instruction from the memory. The execution
cycle interprets the operation and performs the operations specified in the
instruction accordingly.
This cycle repeats until all the instructions are executed from the program and
after the execution of the last instruction the instruction cycle get halt. So, this
was the scenario where there were no interrupts.
Interrupt Cycle
To accommodate the occurrence of interrupts the interrupt cycle must be
added to amend the structure of the instruction cycle. As in the figure below
you can see the interrupt cycle has been added to the basic instruction cycle.
Consider the condition that the interrupts are enabled. In this case, if an
interrupt occurs then the processor halt the execution of the current program.
Thereby it saves the address of the instruction that has to be executed next
and service the occurred interrupt.
To process the interrupts the processor set the program counter with starting
address of the interrupt service routine. This would let the processor fetch the
first instruction of interrupt service routine and service the occurred interrupt.
Once the interrupt is serviced the processor resumes back to the execution of
the program it has halted to service the interrupt. It set the program counter
with the address of the next instruction to be executed.
If the interrupts are disabled then the processor will simply ignore the
occurrence of interrupts. The processor will smoothly execute the currently
running program and will check the pending interrupts once the interrupts are
enabled.
Indirect Cycle
An instruction may have one or more than one operands. To operate these
operands its value is accessed from the memory. So, to execute the
instructions with operands we require memory access. Now, what if indirect
addressing is used?
Instruction execution :
Instruction execution needs the following steps, which are
PC (program counter) register of the processor gives the address of the
instruction which needs to be fetched from the memory.
If the instruction is fetched then, the instruction opcode is decoded. On
decoding, the processor identifies the number of operands. If there is any
operand to be fetched from the memory, then that operand address is
calculated.
Operands are fetched from the memory. If there is more than one operand,
then the operand fetching process may be repeated (i.e. address calculation
and fetching operands).
After this, the data operation is performed on the operands, and a result is
generated.
If the result has to be stored in a register, the instructions end here.
If the destination is memory, then first the destination address has to be
calculated. Then the result is then stored in the memory. If there are multiple
results which need to be stored inside the memory, then this process may
repeat (i.e. destination address calculation and store result).
Now the current instructions have been executed. Side by side, the PC is
incremented to calculate the address of the next instruction.
The above instruction cycle then repeats for further instructions.
Program Control
Program Control has different types of Instructions. Program Control
Instructions are the machine code that are used by machine or in assembly
language by user to command the processor act accordingly. These
instructions are of various types. These are used in assembly language by user
also. But in level language, user code is translated into machine code and thus
instructions are passed to instruct the processor do the task.
Types of Program Control Instructions:
There are different types of Program Control Instructions:
1. Compare Instruction:
Compare instruction is specifically provided, which is similar to a subtract
instruction except the result is not stored anywhere, but flags are set according
to the result.
Example:
CMP R1, R2 ;
2. Unconditional Branch Instruction:
It causes an unconditional change of execution sequence to a new location.
Example:
JUMP L2
Mov R3, R1 goto L2
3. Conditional Branch Instruction:
A conditional branch instruction is used to examine the values stored in the
condition code register to determine whether the specific condition exists and to
branch if it does.
Example:
Assembly Code : BE R1, R2, L1
Compiler allocates R1 for x and R2 for y
High Level Code: if (x==y) goto L1;
4. Subroutines:
A subroutine is a program fragment that lives in user space, performs a well-
defined task. It is invoked by another user program and returns control to the
calling program when finished.
Example:
CALL and RET
5. Halting Instructions:
6. Interrupt Instructions:
Interrupt is a mechanism by which an I/O or an instruction can suspend the
normal execution of processor and get itself serviced.
RESET – It reset the processor. This may include any or all setting registers
to an initial value or setting program counter to standard starting location.
TRAP – It is non-maskable edge and level triggered interrupt. TRAP has the
highest priority and vectored interrupt.
INTR – It is level triggered and maskable interrupt. It has the lowest priority.
It can be disabled by resetting the processor.
Earlier when programming was done using assembly language, a need was felt
to make instruction do more tasks because programming in assembly was
tedious and error-prone due to which CISC architecture evolved but with the
uprise of high-level language dependency on assembly reduced RISC
architecture prevailed.
Characteristic of RISC –
1. Simpler instruction, hence simple instruction decoding.
2. Instruction comes undersize of one word.
3. Instruction takes a single clock cycle to get executed.
4. More general-purpose registers.
5. Simple Addressing Modes.
6. Fewer Data types.
7. A pipeline can be achieved.
Characteristic of CISC –
1. Complex instruction, hence complex instruction decoding.
2. Instructions are larger than one-word size.
3. Instruction may take more than a single clock cycle to get executed.
4. Less number of general-purpose registers as operations get performed in
memory itself.
5. Complex Addressing Modes.
6. More Data types.
Example – Suppose we have to add two 8-bit numbers:
CISC approach: There will be a single command or instruction for this like
ADD which will perform the task.
RISC approach: Here programmer will write the first load command to load
data in registers then it will use a suitable operator and then it will store the
result in the desired location.
So, add operation is divided into parts i.e. load, operate, store due to which
RISC programs are longer and require more memory to get stored but require
fewer transistors due to less complex command.
Difference –
RISC CISC
Can perform only Register to Register Can perform REG to REG or REG to MEM or
Arithmetic operations MEM to MEM
In this section, we will discuss the types of pipelining, pipelining hazards, its
advantage. So let us start.
Introduction
Have you ever visited an industrial plant and see the assembly lines over
there? How a product passes through the assembly line and while passing it
is worked on, at different phases simultaneously. For example, take a car
manufacturing plant. At the first stage, the automobile chassis is prepared, in
the next stage workers add body to the chassis, further, the engine is
installed, then painting work is done and so on.
The group of workers after working on the chassis of the first car don’t sit idle.
They start working on the chassis of the next car. And the next group take the
chassis of the car and add body to it. The same thing is repeated at every
stage, after finishing the work on the current car body they take on next car
body which is the output of the previous stage.
Here, though the first car is completed in several hours or days, due to the
assembly line arrangement it becomes possible to have a new car at the end
of an assembly line in every clock cycle.
Similarly, the concept of pipelining works. The output of the first pipeline
becomes the input for the next pipeline. It is like a set of data processing unit
connected in series to utilize processor up to its maximum.
Look at the figure below the 5 instructions are pipelined. The first instruction
gets completed in 5 clock cycle. After the completion of first instruction, in
every new clock cycle, a new instruction completes its execution.
Observe that when the Instruction fetch operation of the first instruction is
completed in the next clock cycle the instruction fetch of second instruction
gets started. This way the hardware never sits idle it is always busy in
performing some or other operation. But, no two instructions
can execute their same stage at the same clock cycle.
Types of Pipelining
In 1977 Handler and Ramamoorthy classified pipeline processors depending
on their functionality.
1. Arithmetic Pipelining
2. Instruction Pipelining
Here, the number of instruction are pipelined and the execution of current
instruction is overlapped by the execution of the subsequent instruction. It is
also called instruction lookahead.
3. Processor Pipelining
Here, the processors are pipelined to process the same data stream. The
data stream is processed by the first processor and the result is stored in the
memory block. The result in the memory block is accessed by the second
processor. The second processor reprocesses the result obtained by the first
processor and the passes the refined result to the third processor and so on.
The static pipeline performs a fixed-function each time. The static pipeline is
unifunctional. The static pipeline executes the same type of instructions
continuously. Frequent change in the type of instruction may vary the
performance of the pipelining.
Scalar pipelining processes the instructions with scalar operands. The vector
pipeline processes the instruction with vector operands.
In the hardwired control unit, the execution of operations is much faster, but the
implementation, modification, and decoding are difficult. In contrast, implementing,
modifying, decoding micro-programmed control units is very easy. The micro-
programmed control unit is also able to handle complex instructions. With the help of
control signals generated by micro-programmed and hardwired control units, we are
able to fetch and execute the instructions.
Control Signals
In order to generate the control signals, both the control signals were basically
designed. The functionality of a processor's hardware is operated with the help of these
control signals. The control signals are used to know about various types of things,
which are described as follows:
The image of a hardwired control unit is described as follows, which contains various
components in the form of circuitry. We will discuss them one by one so that we can
properly understand the "generation of control signals".
o The instruction register is a type of processor register used to contain an instruction
that is currently in execution. As we can see, the instruction register is used to generate
the OP-code bits respective of the operation as well as the addressing mode of
operands.
o The above generated Op-code bits are received in the field of an instruction decoder.
The instruction decoder interprets the operation and instruction's addressing mode. Now
on the basis of the addressing mode of instruction and operation which exists in the
instruction register, the instruction decoder sets the corresponding Instruction signal
INSi to 1. Some steps are used to execute each instruction, i.e., instruction
fetch, decode, operand fetch, Arithmetic and logical unit, and memory store.
Different books might be contained different steps. But in general, we are able to
execute an instruction with the help of these five steps.
o The information about the current step of instruction must be known by the control unit.
Now the Step Counter is implemented, which is used to contain the signals from T1,….,
T5. Now on the basis of the step which contains the instruction, one of the signals of a
step counter will be set from T1 to T5 to 1.
o Now we have a question that how the step counter knows about the current step of
instruction? So to know the current step, a Clock is implemented. The one-clock cycle of
the clock will be completed for each step. For example, suppose that if the stop counter
sets T3 to 1, then after completing one clock cycle, the step counter will set T4 to 1.
o Now we have a question, i.e., what will happen if the execution of an instruction is
interrupted for some reason? Will the step counter still be triggered by the clock? The
answer to this question is No. As long as the execution is current step is completed,
the Counter Enable will "disable" the Step Counter so that it will stop then increment to
the next step signal.
o Now we have a question, i.e., what if the execution of instruction depends on some
conditions? In this case, the Condition Signals will be used. There are various conditions
in which the signals are generated with the help of control signals that can be less than,
greater than, less than equal, greater than equal, and many more.
o The external input is the last one. It is used to tell the Control Signal Generator about
the interrupts, which will affect the execution of an instruction.
So, on the basis of the input obtained by the conditional signals, step counter, external
inputs, and instruction register, the control signals will be generated with the help of
Control signal Generator.
Now we will learn about the organization of Micro-program CU. Then we will learn
about the flow of instruction execution with the help of instruction execution steps,
which are described as follows:
o Instruction fetch is the first step. In this step, the instruction is fetched from the IR
(Instruction Register) with the help of a Microinstruction address register.
o Decode is the second step. In this step, the instructions obtained from the instruction
register will be decoded with the help of a microinstruction address generator. Here we
will also get the starting address of a micro-routine. With the help of this address, we can
easily perform the operation, which is mentioned in the instruction. It will also load the
starting address into the micro-program counter.
o Increment is the third step. In this step, the control word, which corresponds to the
starting address of a micro-program, will be read. When the execution proceeds, the
value of the micro-program counter will be increased so that it can read the successive
control words of a micro-routine.
o End bit is the fourth step. In this step, the microinstruction of a micro-routine contains a
bit, which is known as the end bit. The execution of the microinstruction will be
successfully completed when the end bit is set to 1.
o This is the last step, and in this step, the micro-program address generator will again go
back to Step 1 so that we can fetch a new instruction, and this process or cycle goes on.
So in the micro-programmed control unit, the micro-programs are stored with the help
of Control memory or Control store. The implementation of this CU is very easy and
flexible, but it is slower as compared to the Hardwired control unit.