Unit 2 (Coa) Notes
Unit 2 (Coa) Notes
When the control signals are generated by hardware using conventional logic design techniques, the control
unit is said to be hardwired.
The key characteristics are
oHigh speed of operation
oExpensive
oRelatively complex
oNo flexibility of adding new instructions
Examples of CPU with hardwired control unit are Intel 8085, Motorola 6802, Zilog 80, and any RISC
A computer with a microprogrammed control unit will have two separate memories: a main memory and a
control memory
The microprogram consists of microinstructions that specify various internal control signals for execution of
register microoperations
These microinstructions generate the microoperations to:
fetch the instruction from main memory
evaluate the effective address
execute the operation
return control to the fetch phase for the next instruction
2. Address Sequencing:
Microinstructions are stored in control memory in groups, with each group specifying a routine.
Each computer instruction has its own microprogram routine to generate the microoperations.
The hardware that controls the address sequencing of the control memory must be capable of sequencing the
microinstructions within a routine and be able to branch from one routine to another
Steps the control must undergo during the execution of a single computer instruction:
o Load an initial address into the CAR when power is turned on in the computer. This address is usually
the address of the first microinstruction that activates the instruction fetch routine – IR holds
instruction
o The control memory then goes through the routine to determine the effective address of the operand
– AR holds operand address
o The next step is to generate the microoperations that execute the instruction by considering the
opcode and applying a mapping process.
The transformation of the instruction code bits to an address in control memory where the
routine of instruction located is referred to as mapping process.
o After execution, control must return to the fetch routine by executing an unconditional branch
In brief the address sequencing capabilities required in a control memory are:
o Incrementing of the control address register.
o Unconditional branch or conditional branch, depending on status bit conditions.
o A mapping process from the bits of the instruction to an address for control memory.
2
Page
o A facility for subroutine call and return.
The below figure shows a block diagram of a control memory and the associated hardware needed for
selecting the next microinstruction address.
The microinstruction in control memory contains a set of bits to initiate microoperations in computer registers
and other bits to specify the method by which the next address is obtained.
In the figure four different paths form which the control address register (CAR) receives the address.
o The incrementer increments the content of the control register address register by one, to select the
next microinstruction in sequence.
o Branching is achieved by specifying the branch address in one of the fields of the microinstruction.
o Conditional branching is obtained by using part of the microinstruction to select a specific status bit in
order to determine its condition.
o An external address is transferred into control memory via a mapping logic circuit.
o The return address for a subroutine is stored in a special register, that value is used when the
micoprogram wishes to return from the subroutine.
Conditional Branching:
Conditional branching is obtained by using part of the microinstruction to select a specific status bit in order to
determine its condition.
The status conditions are special bits in the system that provide parameter information such as the carry-out of
an adder, the sign bit of a number, the mode bits of an instruction, and i/o status conditions.
The status bits, together with the field in the microinstruction that specifies a branch address, control the
branch logic.
3
Page
The branch logic tests the condition, if met then branches, otherwise, increments the CAR.
If there are 8 status bit conditions, then 3 bits in the microinstruction are used to specify the condition and
provide the selection variables for the multiplexer.
For unconditional branching, fix the value of one status bit to be one load the branch address from control
memory into the CAR.
Mapping of Instruction:
A special type of branch exists when a microinstruction specifies a branch to the first word in control memory
where a microprogram routine is located.
The status bits for this type of branch are the bits in the opcode.
Assume an opcode of four bits and a control memory of 128 locations. The mapping process converts the 4-bit
opcode to a 7-bit address for control memory shown in below figure.
Mapping consists of placing a 0 in the most significant bit of the address, transferring the four
operation code bits, and clearing the two least significant bits of the control address register.
This provides for each computer instruction a microprogram routine with a capacity of four microinstructions.
Subroutines:
Subroutines are programs that are used by other routines to accomplish a particular task and can be called
from any point within the main body of the microprogram.
Frequently many microprograms contain identical section of code.
Microinstructions can be saved by employing subroutines that use common sections of microcode.
Microprograms that use subroutines must have a provision for storing the return address during a subroutine
call and restoring the address during a subroutine return.
A subroutine register is used as the source and destination for the addresses
3. Microprogram Example:
The process of code generation for the control memory is called microprogramming.
The block diagram of the computer configuration is shown in below figure.
Two memory units:
Main memory – stores instructions and data
Control memory – stores microprogram
Four processor registers
Program counter – PC
Address register – AR
Data register – DR
Accumulator register - AC
Two control unit registers
Control address register – CAR
Subroutine register – SBR
Transfer of information among registers in the processor is through MUXs rather than a bus.
4
Page
The computer instruction format is shown in below figure.
The example will only consider the following 4 of the possible 16 memory instructions
The microinstruction format for the control memory is shown in below figure.
5
Page
The microinstruction format is composed of 20 bits with four parts to it
Three fields F1, F2, and F3 specify microoperations for the computer [3 bits each]
The CD field selects status bit conditions [2 bits]
The BR field specifies the type of branch to be used [2 bits]
The AD field contains a branch address [7 bits]
Each of the three microoperation fields can specify one of seven possibilities.
No more than three microoperations can be chosen for a microinstruction.
If fewer than three are needed, the code 000 = NOP.
The three bits in each field are encoded to specify seven distinct microoperations listed in below table.
The branch field (BR) consists of two bits and is used with the address field to choose the address of the
next microinstruction.
6
Page
Each line of an assembly language microprogram defines a symbolic microinstruction and is divided into five
parts
1. The label field may be empty or it may specify a symbolic address. Terminate with a colon (: ).
2. The microoperations field consists of 1-3 symbols, separated by commas. Only one symbol from each
field. If NOP, then translated to 9 zeros
3. The condition field specifies one of the four conditions
4. The branch field has one of the four branch symbols
5. The address field has three formats
a. A symbolic address – must also be a label
b. The symbol NEXT to designate the next address in sequence
c. Empty if the branch field is RET or MAP and is converted to 7 zeros
The symbol ORG defines the first address of a microprogram routine.
ORG 64 – places first microinstruction at control memory 1000000.
Fetch Routine:
The control memory has 128 locations, each one is 20 bits.
The first 64 locations are occupied by the routines for the 16 instructions, addresses 0-63.
Can start the fetch routine at address 64.
The fetch routine requires the following three microinstructions (locations 64-66).
The microinstructions needed for fetch routine are:
7
Page
4. Design of control Unit:
The control memory out of each subfield must be decoded to provide the distinct microoperations.
The outputs of the decoders are connected to the appropriate inputs in the processor unit.
The below figure shows the three decoders and some of the connections that must be made from their
outputs.
The three fields of the microinstruction in the output of control memory are decoded with a 3x8 decoder to
provide eight outputs.
Each of the output must be connected to proper circuit to initiate the corresponding microoperation as
specified in previous topic.
When F1 = 101 (binary 5), the next pulse transition transfers the content of DR (0-10) to AR.
Similarly, when F1= 110 (binary 6) there is a transfer from PC to AR (symbolized by PCTAR). As
shown in Fig, outputs 5 and 6 of decoder F1 are connected to the load input of AR so that when
either one of these outputs is active, information from the multiplexers is transferred to AR.
The multiplexers select the information from DR when output 5 is active and from PC when
output 5 is inactive.
The transfer into AR occurs with a clock transition only when output 5 or output 6 of the decoder is
active.
For the arithmetic logic shift unit the control signals are instead of coming from the logical gates,
now these inputs will now come from the outputs of AND, ADD and DRTAC respectively.
Microprogram Sequencer:
The basic components of a microprogrammed control unit are the control memory and the circuits that select
the next address.
The address selection part is called a microprogram sequencer.
The purpose of a microprogram sequencer is to present an address to the control memory so that a
microinstruction may be read and executed.
The next-address logic of the sequencer determines the specific address source to be loaded into the control
address register.
The block diagram of the microprogram sequencer is shown in below figure.
The control memory is included in the diagram to show the interaction between the sequencer and the
memory attached to it.
There are two multiplexers in the circuit.
o The first multiplexer selects an address from one of four sources and routes it into control address
register CAR.
o The second multiplexer tests the value of a selected status bit and the result of the test is applied to an
input logic circuit.
The output from CAR provides the address for the control memory.
8
Page
The content of CAR is incremented and applied to one of the multiplexer inputs and to the subroutine register
SBR.
The other three inputs to multiplexer come from
o The address field of the present microinstruction
o From the out of SBR
o From an external source that maps the instruction
The CD (condition) field of the microinstruction selects one of the status bits in the second multiplexer.
If the bit selected is equal to 1, the T variable is equal to 1; otherwise, it is equal to 0.
The T value together with two bits from the BR (branch) field goes to an input logic circuit.
The input logic in a particular sequencer will determine the type of operations that are available in the unit.
The input logic circuit in above figure has three inputs I0, I1, and T, and three outputs, S0, S1, and L.
Variables S0 and S1 select one of the source addresses for CAR. Variable L enables the load input in SBR.
The binary values of the selection variables determine the path in the multiplexer.
For example, with S1,S0 = 10, multiplexer input number 2 is selected and establishes transfer path from SBR to
CAR.
The truth table for the input logic circuit is shown in Table below.
9
Part-II: Central Processing Unit
The Central Processing Unit (CPU) is called the brain of the computer that performs data-
processing operations. Figure below shows the three major parts of CPU.
Intermediate data is stored in the register set during the execution of the instructions. The micro
operations required for executing the instructions are performed by the arithmetic logic unit
whereas the control unit takes care of transfer of information among the registers and guides the
ALU. The control unit services the transfer of information among the registers and instructs the
ALU about which operation is to be performed. The computer instruction set is meant for
providing the specifications for the design of the CPU. The design of the CPU largely, involves
choosing the hardware for implementing the machine instructions.
The need for memory locations arises for storing pointers, counters, return address,
temporary results and partial products. Memory access consumes the most of the time off an
operation in a computer. It is more convenient and more efficient to store these intermediate values
in processor registers.
A common bus system is employed to contact registers that are included in the CPU in a
large number. Communications between registers is not only for direct data transfer but also for
performing various micro-operations. A bus organization for such CPU register shown in below
Figure, is connected to two multiplexers (MUX) to form two buses A and B. The selected lines in
each multiplexers select one register of the input data for the particular bus.
10
·
Control Word
11
Encoding of register selection fields
Symbolic Designation
Microoperation SELA SELB SELD OPR Control Word
12
Instruction Formats:
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.
A stack-based computer does not use the address field in the instruction. To evaluate an expression first it is
converted to reverse Polish Notation i.e. Postfix Notation.
Expression: X = (A+B)*(C+D)
Postfixed : X= AB+CD+*
TOP means top of stack
M[X] is any memory location
PUSH A TOP ← A
PUSH B TOP ← B
PUSH C TOP ← C
PUSH D TOP ← D
13
2 .One Address Instructions –
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.
Expression: X= (A+B)*(C+D)
AC is accumulator
M[X] 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
MUL R1, R2 R1 ← R1 * R2
MOV X, R1 M[X] ← R1
5.RISC Instructions
The instruction set of a typical RISC(Reduced Instruction Set Computer) processor is restricted to the use of
load and store instructions when communicating between memory and CPU.
Expression: X= (A+B)*(C+D)
R1, R2,R3,R4 are registers
M[X] is any memory location
ADD R1,R1,R2 R1 ← R1 + R2
ADD R3,R3,R4 R3 ← R3 + R4
STORE X R1 M[X] ← R1
15
ADDRESSING MODES :
* Specifies a rule for interpreting or modifying the address field of the instruction (before the operand is
actually referenced)
Immediate Mode − In this mode, the operand is specified in the instruction itself. In other words, an immediate-mode
instruction has an operand field instead of an address field. The operand field includes the actual operand to be used in
conjunction with the operation determined in the instruction. Immediate-mode instructions are beneficial for initializing
registers to a constant value.
Register Mode − In this mode, the operands are in registers that reside within the CPU. The specific register is selected
from a register field in the instruction. A k-bit field can determine any one of the 2k registers.
Register Indirect Mode − In this mode, the instruction defines a register in the CPU whose contents provide the address
of the operand in memory. In other words, the selected register includes the address of the operand rather than the
operand itself.
A reference to the register is then equivalent to specifying a memory address. The advantage of a register indirect mode
instruction is that the address field of the instruction uses fewer bits to select a register than would have been required to
specify a memory address directly.
Autoincrement or Autodecrement Mode &minuend; This is similar to the register indirect mode except that the register
is incremented or decremented after (or before) its value is used to access memory. When the address stored in the
register defines a table of data in memory, it is necessary to increment or decrement the register after every access to the
table. This can be obtained by using the increment or decrement instruction.
Direct Address Mode − In this mode, the effective address is equal to the address part of the instruction. The operand
resides in memory and its address is given directly by the address field of the instruction. In a branch-type instruction, the
address field specifies the actual branch address.
16
Indirect Address Mode − In this mode, the address field of the instruction gives the address where the effective address
is stored in memory. Control fetches the instruction from memory and uses its address part to access memory again to
read the effective address.
Indexed Addressing Mode − In this mode, the content of an index register is added to the address part of the instruction
to obtain the effective address. The index register is a special CPU register that contains an index value. The address
field of the instruction defines the beginning address of a data array in memory.
Numerical Example:
To show the differences between the various modes, we will show the effect of the addressing modes on the
instruction defined in Fig. 7.
The two-word instruction at address 200 and 201 is a "load to AC" instruction with an address field equal to 500.
The first word of the instruction specifies the operation code and mode, and the second word specifies the
address part.
PC has the value 200 for fetching this instruction. The content of processor register R1 is 400, and the content of
an index register XR is 100.
AC receives the operand after the instruction is executed. The figure lists a few pertinent addresses and shows
the memory content at each of these addresses.
The mode field of the instruction can specify any one of a number of modes. For each possible mode we
calculate the effective address and the operand that must be loaded into AC.
In the direct address mode the effective address is the address part of the instruction 500 and the operand to be
loaded into AC is 800. In the immediate mode the second word of the instruction is taken as the operand rather
than an address, so 500 is loaded into AC. (The effective address in this case is 201 .)
In the indirect mode the effective address is stored in memory at address 500. Therefore, the effective address is
800 and the operand is 300. In the relative mode the effective address is 500 + 202 = 702 and the operand is
325.
17
(Note that the value in PC after the fetch phase and during the execute phase is 202.) In the index mode the
effective address is XR + 500 = 100 + 500 = 600 and the operand is 900. In the register mode the operand is in
R1 and 400 is loaded into AC.
(There is no effective address in this case.) In the register indirect mode the effective address is 400, equal to the
content of R1 and the operand loaded into AC is 700.
The autoincrement mode is the same as the register indirect mode except that R1 is incremented to 401 after the
execution of the instruction. The autodecrement mode decrements R1 to 399 prior to the execution of the
instruction.
The operand loaded into AC is now 450. Table 4 lists the values of the effective address and the operand loaded
into AC for the nine addressing modes.
18
Table : Typical Data Transfer Instructions
19
It will decrement the register B by 1
B<-B-1
Decrement DEC DEC B
20
It will negate a value by finding 2’s complement
of its single operand.
This means simply operand by -1.
Negate(2’s
B<-B’+1
complement) NEG NEG B
2. Logical and Bit Manipulation Instructions :
Logical instructions perform binary operations on strings of bits stored in registers. They are useful for manipulating
individual bits or a group of bits.
Typical Logical and Bit Manipulation Instructions –
Name MnemonicExample Explanation
It will set the accumulator to 0
AC<-0
Clear CLR CLR
It will AND the contents of register B with the contents of accumulator and
store
it in the accumulator
AC<-AC AND B
AND AND AND B
in the accumulator
AC<-AC OR B
OR OR OR B
It will XOR the contents of register B with the contents of the accumulator
and
store it in the accumulator
AC<-AC XOR B
Exclusive-OR XOR XOR B
21
Enable interrupt EI EI It will enable the interrupt
PROGRAM CONTROL
Program control instructions specify conditions for altering the content of the program counter , while data transfer and
manipulation instructions specify condtions for data-processing operations.
NAME Mnemonic
Branch BR
Jump JMP
Skip SKP
Call CALL
Return RET
22
Status Bit Conditions:
• It is convinent to supplement the ALU circuit in the CPU with a status register where status bit condition can be
stored for further analysis.
• Status bits are also called condition code bit or flag bit.
• The four status bits are symbolized by C,S,Z and V.
• The bits are set or cleared as a result of an operation performed in the ALU
23
Subroutine Call and Return:
CALL:
SP← SP-1: Decrement stack point
M[SP] ←PC : Push content of PC onto the stack
PC←Effective Address : Transfer control to the subroutine
RETURN:
PC ← M[SP] : Pop stack and transfer to PC
SP ← SP+1 : Increment stack pointer
Program Interrupt:
» Transfer program control from a currently running program to another service program
as a result of an external or internal generated request
» Control returns to the original program after the service program is executed
Types of Interrupts:
1) External Interrupts
» come from I/O device, from a timing device, from a circuit
monitoring the power supply, or from any other external source
2) Internal Interrupts or TRAP
» caused by register overflow, attempt to divide by zero,
an invalid operation code, stack overflow, and protection violation
3) Software Interrupts
» initiated by executing an instruction (INT or RST)
» used by the programmer to initiate an interrupt procedure at any desired point in the program
24