Co Unit-Ii
Co Unit-Ii
Computer programs are written in many programming languages, like C++, Java, or Visual
Basic. A Computer can only understand machine language (0,1). Each computer has its own
specific machine language. A computer cannot directly understand the programming
languages, so the program code must be converted into machine language using compiler or
interpreter. For example of machine language (binary) for the text "Hello World."
Machine language is a series of 0 and 1, which is not easy for humans to read. Using
Assembly language, programmers can write human-readable programs. Assembly is a low-
level programming language. It uses short codes (mnemonics) to write the programs for
example ADD R1, R2. In computers, there is an assembler that converts the assembly code
into machine code.
1
Example
ALGORITHM
SOURCE CODE
Types of Assemblers
2
2. Multi-pass assembler: This assembler scans a source code several times to generate
machine code. This final pass is called a synthesis pass. It is slower than a single-pass
assembler.
There is various difference between Machine Language and Assembly Language. A table is given
below that contains all differences between them.
Machine language includes binary Mnemonics such as Mov, Add, Sub, End, and
digits (0s and 1s), hexadecimal and others make up the assembly language, which
octal numbers people can understand, utilise, and apply.
The sequences of bits are used by Assembly language uses "mnemonics" names
Machine language to give commands. and symbols; therefore, users do not need to
It is dependent on the CPU to the remember op-codes with assembly language.
conversion of high-level
programming language to machine
language.
3
The first-generation programming The second generation of programming
languages are Machine languages, languages is assembly languages, which use
which do not need a translator. assembler as a translator to convert mnemonics
into machine-understandable form.
A program loop is a sequence of instructions that are executed many times. The following is
an example of a Fortran program that forms the sum of 100 integer numbers.
DIMENSION A(100)
INTEGER SUM, A
SUM = 0
DO 3 J = 1, 100
3 SUM = SUM + A(J)
Statement number 3 is executed 100 times. A system program that translates a high-level
program is called a compiler. Following table shows coorecposnding assembly code of the
program
4
11 STA SUM /Store sum
12 HLT /Halt
1 ORG = 100
2 AC= 100
3 PTR = 100
4 AC = -100
5 CTR = -100
6 AC = 0
[4]. Subroutines
In a program, a set of instructions can be used many times. Such a block is called a
subroutine. A subroutine consists of a self-contained sequence of instructions. A subroutine
is called using Branch (BSA) instruction. After the subroutine has been executed, a branch is
made back to the main program. A branch can be made to the subroutine from any part of
the main program.
It is necessary to store the return address for the subroutine to know where to return. For
this, the BSA instruction (branch and save return address) is used in the computer.
Let us write a subroutine that shifts the content of the accumulator four times to the left. The
program of Table starts by loading the value of X into the AC. The next instruction is BSA
SH4. Subroutine SH4 must return to location 102 after it finishes its task. When the BSA
instruction is executed, the control unit stores the return address (102 + 1) in PC.
After this control goes to memory location 109 and execute the subroutine. Due to the last
instruction SH4 I, control come back to main program at the address given by PC which is
102.
5
/Subroutine to shift left 4 times
104 SH4, HEX 0 /Store return address here
105 CIL /Circulate left once
106 CIL
107 CIL
108 CIL /Circulate left fourth time
109 BUN SH4 I /Return to main program
END
The symbols are strings of characters and each character is of 8-bit long. When user presses
a charter on keyboard then an INP (input) instruction is executed. To display a character an
OUT (output) instruction is executed. The output device detects the binary code and types
the corresponding character.
Table-A lists the instructions needed to input a character and store it in memory.
The SKI instruction checks the input flag to see if a character is available for transfer.
If a character is available then the input flag bit is 1 otherwise it is 0.
The INP instruction transfers the character into AC. The character is then printed by
means of the OUT instruction.
If the SKI instruction finds the flag bit = 0, the next instruction in sequence is
executed. This instruction is a branch to return and check the flag bit again.
6
HLT
The main functional units of CPU are control unit, arithmetic and logic unit, and registers.
The function of the control unit in a digital computer is to initiate sequences of
microoperations. It creates a control words. A control word is a group of 0’s and 1’s. A
control words is a signal for various functional components of a computer.
The memory present in Conrol Unit is called control Memory. It stores Microprograms.
Microprograms are collection of Micro Instructions. One Micro Instruction conatins one or
more micro-operation (such as ADD, SUB, TSA, MUL).
Control Unit can be designed in 2 ways: 1) Hardwired Control Unit, 2) Micro Programmed
Control Unit.
The contents of main memory may change but contents of the control memory cannot be
changed bu user. The general configuration of a microprogrammed control unit is shown
below:
The control memory stores all control information. The control memory address
register (CAR) gives the address of microinstruction which is stored in Control
Memory.
The Control Data Register (CDR)holds the data fetched from control memory.
For example, Let Control Memory address reg. has 010. Then the data 1101 will be
sent to Control Data Register.
After this address of next microinstruction is fetched from Next Address Generator
(Sequencer).
7
001 1100
010 1101
011 0010
100 1110
In this topic, we will discuss how address of next instruction is fetched by Sequencer.
1. Incrementing CAR by 1
2. Subroutine call
3. Unconditional/ Conditional branch
4. Mapping
1. Incrementing CAR by 1
In this method contents of CAR is incremented by 1. This new value is the address of next
instruction.
2. Subroutine call
Subroutines are like functions in a C program. Subroutines have the instructions that
execute many times.
When the function is called, the address in next instruction is stored in
Subroutine Register.
Then program control goes to subroutine (function definition) and execute it.
8
When the subroutine is completed then the address which is stored in
Subroutine Register is used to find the address of next instruction in the
program.
3. Unconditional/ Conditional branch
In unconditional branch instruction, no condition is matched but in Conditional branch
instruction a condition must be true for branching. In both condition, some flag bits
(Status bits) are checked and we get the address of next instruction.
4. Mapping
In this some mapping functions are used to know the address of next instruction in the
program.
9
[8]. Design of Control Unit
The CPU usually has two main systems: control unit (CU) and arithmetic and logic
unit (ALU). The control unit (CU) is used to synchronize the tasks with the help of sending
timings and control signals. On the other hand, mathematical and logical operations can be
handled with the help of ALU. Micro programmed control units and hardwired control units
can be called two types of control units. We can execute an instruction with the help of these
two control units.
Control Signals
The control signals are used to know about various types of things, which are described as
follows:
The hardwired control unit generating control signals to execute the instructions at a correct
time and proper sequence. As compared to the micro-programmed, the hardwired CU is
generally faster. In this, the control signals are generated with the help of PLA circuit and
state counter. With the help of hardware, the hardwired control signals are generated, and it
basically uses the circuitry approach.
The image of a hardwired control unit is described as follows. We will discuss them one by
one so that we can properly understand the "generation of control signals".
10
o The instruction register It 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
11
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.
A micro-programmed control unit can be described as a simple logic circuit. We can use it in
two ways, i.e., it is able to execute each instruction with the help of generating control
signals, and it is also able to do sequencing through microinstructions. It will generate the
control signals with the help of programs. At the time of evolution of CISC architecture in
the past, this approach was very famous. The program which is used to create the control
signals is known as the "Micro-program". The micro-program is placed on the processor
chip, which is a type of fast memory. This memory is also known as the control store or
control memory.
Like the above, the instruction execution in a micro-programmed control unit is also
performed in steps. So for each step, the micro-program contains a control word/
microinstruction. If we want to execute a particular instruction, we need a sequence of
microinstructions. This process is known as the micro-routine. The image of a micro-
programmed control unit is described as follows. Here, we will learn the organization of
micro-program, micro-routine, and control word/ microinstruction.
12
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:
13
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.
14
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.
There are various differences between Micro-programmed CU and Hardwired CU, which
are described as follows:
With the help of a hardware circuit, we can While with the help of programming, we can implement
implement the hardwired control unit. In the micro-programmed control unit.
other words, we can say that it is a
circuitry approach.
The hardwired control unit uses the logic The micro-programmed CU uses microinstruction so
circuit so that it can generate the control that it can generate the control signals. Usually, control
signals, which are required for the memory is used to store these microinstructions.
processor.
In this CU, the control signals are going to It is very easy to modify the micro-programmed control
be generated in the form of hard wired. unit because the modifications are going to be
That's why it is very difficult to modify the performed only at the instruction level.
hardwired control unit.
In the form of logic gates, everything has The micro-programmed control unit is less costly as
to be realized in the hardwired control unit. compared to the hardwired CU because this control unit
That's why this CU is more costly as only requires the microinstruction to generate the
compared to the micro-programmed control signals.
control unit.
The complex instructions cannot be The micro-programmed control unit is able to handle
handled by a hardwired control unit the complex instructions.
because when we design a circuit for this
instruction, it will become complex.
Because of the hardware implementation, The micro-programmed control unit is able to generate
the hardwired control unit is able to use a control signals for many instructions.
limited number of instructions.
The hardwired control unit is used in those The micro-programmed control unit is used in those
types of computers that also use the RISC types of computers that also use the CISC (Complex
(Reduced instruction Set Computers). instruction Set Computers).
In the hardwired control unit, the hardware In this CU, the microinstructions are used to generate
is used to generate only the required the control signals. That's why this CU is slower than
control signals. That's why this control unit the hardwired control unit.
15
is faster as compared to the micro-
programmed control unit.
Hardwired control unit is faster when compared to This is slower than the other as micro
microprogrammed control unit as the required control instructions are used for generating signals
signals are generated with the help of hardwares here
Difficult to modify as the control signals that need to Easy to modify as the modification need to be
be generated are hard wired done only at the instruction level
Only limited number of instructions are used due to Control signals for many instructions can be
the hardware implementation generated
16