Professional Documents
Culture Documents
Micro-programmed control
Looping
Outline
• Control Memory
• Address Sequencing
• Micro-instruction Code Format
• General Register Organization
• Stack Organization
• Instruction format
• Addressing Modes
• Data transfer and manipulation
• Program Control
• Reduced Instruction Set Computer (RISC)
• Complex Instruction Set Computer (CISC)
Section - 1
Control Memory
1 CONTROL MEMORY
Hardwire Control vs. Microprogrammed Control :
• The function of the control unit in a digital computer is to initiate sequences
of microoperations, The number of different types of microoperations that are
available in a given system is finite. The complexity of the digital system is
derived from the number of sequences of microoperations that are performed.
• When the control signals are generated by hardware using conventional logic
design techniques, the control unit is said to be hardwired.
• Microprogramming is a second alternative for designing the control unit of a
digital computer. The principle of microprogramming is an elegant and
systematic method for controlling the microoperation sequences in a digital
computer.
Control Memory
• Hardwired
Memory Instruction code
Combinational . Control
Sequence Counter
Logic Circuits . signals
• Microprogrammed
CAR: Control Address Register
Memory Instruction code CDR: Control Data Register
Microprogrammed Control :
• The control unit initiates a series of sequential steps of microoperations. During any given
time, certain microoperations are to be initiated, while others remain idle. The control
variables at any given time can be represented by a string of l's and 0’s called a control
word. As such, control words can be programmed to perform various operations on the
components of the system.
• A control unit whose binary control variables are stored in memory is called a
microprogrammed control unit.
• Each word in control memory contains within it a microinstruction.
• The microinstruction specifies one or more microoperations for the system.
• A sequence of microinstructions constitutes a microprogram. Since alterations of the
microprogram are not needed once the control unit is in operation, the control memory can
be a read-only memory (ROM).
Control Memory
• If we want to establish a different control sequence for the system, all we need
to do is specify a different set of microinstructions for control memory.
• The hardware configuration should not be changed for different operations; the only
thing that must be changed is the microprogram residing in control memory.
Control Memory
Hardwire Control :
• It should be mentioned that most computers based on the reduced instruction set
computer (RISC) architecture concept use hardwired control rather than a
control memory with a microprogram.
Control Memory
A computer that employs a microprogrammed control unit will have two separate memories: a
main memory and a control memory.
The control memory holds a fixed microprogram that can not be altered by the occasional user.
The microprogram consists of microinstructions that specify various internal control signals
for execution of register microoperation.
External Control
input word
Next-
Control Control Control
address
address memory data
generator
register (ROM) register
(Sequencer)
Next-address information
Control Memory
Control Memory :
• The content of the words in ROM are fixed and cannot be altered by simple
programming since no writing capability is available in the ROM. ROM words are
made permanent during the hardware production of the unit. The use of a
microprogram involves placing all control variables in words of ROM for use by the
control unit through successive read operations. The content of the word in ROM at
a given address specifies a microinstruction.
• A more advanced development known as dynamic microprogramming permits a
microprogram to be loaded initially from an auxiliary memory such as a magnetic
disk. Control units that use dynamic microprogramming employ a writable control
memory. This type of memory can be used for writing (to change the microprogram)
but is used mostly for reading. A memory that is part of a control unit is referred
to as a control memory.
Control Memory
Sequencer :
• The next address generator is sometimes called a microprogram sequencer, as it
determines the address sequence that is read from control memory. The address
of the next microinstruction can be specified in several ways, depending on the
sequencer inputs.
Pipeline Register :
• The control data register holds the present microinstruction while the next address
is computed and read from memory. The data register is sometimes called a
pipeline register.
• This configuration requires a two-phase clock, with one clock applied to the address
register and the other to the data register.
Control Memory
Non-pipeline Microprogrammed Control :
• The system can operate without the control data register by applying a single-
phase clock to the address register.
• The control word and next-address information are taken directly from the control
memory. It must be realized that a ROM operates as a combinational circuit, with the
address value as the input and the corresponding word as the output.
• The content of the specified word in ROM remains in the output wires as long as its
address value remains in the address register. No read signal is needed as in a random-
access memory. Each dock pulse will execute the microoperations specified by the
control word and also transfer a new address to the control address register. In the
example that follows we assume a single-phase clock and therefore we do not use a
control data register.
• In this way the address register is the only component in the control system that
receives dock pulses. The other two components: the sequencer and the control
memory are combinational circuits and do not need a dock.
Section - 2
Address Sequencing
Microinstructions are stored in control memory in groups, with each group specifying a routine.
The transformation from the instruction code bits to an address in control memory where the
routine is located is referred to as a mapping process.
The address sequencing capabilities required in a control memory are:
1. Incrementing of the control address register.
2. Unconditional branch or conditional branch, depending on status bit conditions.
3. A mapping process from the bits of the instruction to an address for control memory.
4. A facility for subroutine call and return.
Address Sequencing
Instruction code
Mapping
logic
Control memory
3 3 3 2 2 7
F1 F2 F3 CD BR AD
BR Symbol Function
00 JMP CAR AD if condition = 1, CAR CAR+1 if condition = 0
01 CALL CAR AD, SBR CAR+1 if condition=1, CAR CAR+1 if condition=0
10 RET CAR SBR (Return from subroutine)
11 MAP CAR(2-5) DR(11-14), CAR(0,1,6) 0
Section - 4
Clock Input
R1
R2
R3
R4
R5
R6
R7
Load
(7 lines) SEL A MUX - A MUX - B SEL B
Output
General Register Organization
Example: R1 R2 + R3
To perform the above operation, the control must provide binary selection variables to the
following selector inputs:
1. MUX A selector (SELA): to place the content of R2 into bus A.
2. MUX B selector (SELB): to place the content of R3 into bus B.
3. ALU operation selector (OPR): to provide the arithmetic addition A + B.
4. Decoder destination selector (SELD): to transfer the content of the output bus into R1.
Control Word:
63
SP ← SP + 1
FULL EMTY
M[SP] ← DR
IF (SP= 0) then (FULL ← 1)
EMTY ← 0
POP Operation 4
SP C 3
DR ← M[SP] 2
B
SP ← SP - 1 A 1
0
IF (SP= 0) then (EMTY ← 1)
FULL ← 0 DR
Register Stack
A stack can be placed in a portion of a large memory or it can be organized as a collection of a
finite number of memory words or registers. Figure shows the organization of a 64-word
register stack.
The stack pointer register SP contains a binary number whose value is equal to the address of
the word that is currently on top of the stack.
In a 64-word stack, the stack pointer contains 6 bits because 26 = 64.
Since SP has only six bits, it cannot exceed a number greater than 63 (111111 in binary).
The one-bit register FULL is set to 1 when the stack is full, and the one-bit register EMTY is set
to 1 when the stack is empty of items.
DR is the data register that holds the binary data to be written into or read out of the stack.
Memory Stack
Address
PUSH Operation
PC Program 1000
SP ← SP - 1 (instructions)
AR Data 2000
M[SP] ← DR (operands)
3000
POP Operation Stack
3997
DR ← M[SP]
SP 3998
SP ← SP + 1
3999
4000
4001
DR
Memory Stack
The implementation of a stack in the CPU is done by assigning a portion of memory to a stack
operation and using a processor register as a stack pointer.
Figure shows a portion of computer memory partitioned into three segments: program, data,
and stack.
The program counter PC points at the address of the next instruction in the program which is
used during the fetch phase to read an instruction.
The address registers AR points at an array of data which is used during the execute phase to
read an operand.
The stack pointer SP points at the top of the stack which is used to push or pop items into or
from the stack.
We assume that the items in the stack communicate with a data register DR.
Reverse Polish Notation
The common mathematical method of writing arithmetic expressions imposes difficulties when
evaluated by a computer.
The Polish mathematician Lukasiewicz showed that arithmetic expressions can be represented
in prefix notation as well as postfix notation.
A*B+C*D AB * CD * +
Reverse Polish
Evaluation of Arithmetic Expression
(3 * 4) + (5 * 6) 34*56*+ 42
4 5 5 30
3 3 12 12 12 12 42
3 4 * 5 6 * +
Section - 6
Instruction Formats
Instructions are categorized into different formats with respect to the operand fields in the
instructions.
1. Three Address Instructions
2. Two Address Instruction
3. One Address Instruction
4. Zero Address Instruction
5. RISC Instructions
Three Address Instruction
Computers with three-address instruction formats can use each address field to specify either
a processor register or a memory operand.
The program in assembly language that evaluates X = (A + B) * (C + D) is shown below.
ADD R1, A, B R1← M[A]+ M[B]
ADD R2, C, D R2← M[C]+ M[D]
MUL X, R1, R2 M[X]← R1 * R2
The advantage of three-address format is that it results in short programs when evaluating
arithmetic expressions.
The disadvantage is that the binary-coded instructions require too many bits to specify three
addresses.
Two Address Instruction
Two address instructions are the most common in commercial computers. Here again each
address field can specify either a processor register or a memory word.
The program to evaluate X = (A + B) * (C + D) is as follows:
AC
500 800
600 900
702 325
800 300
Section - 8
Data transfer and manipulation
The data manipulation instructions in a typical computer are usually divided into three
basic types:
1. Arithmetic instructions
2. Logical and bit manipulation instructions
3. Shift instructions
Data manipulation instructions
Logical & Bit
Arithmetic Instructions Manipulation Instructions Shift Instructions
Name Mnemonic Name Mnemonic Name Mnemonic
Increment INC Clear CLR Logical shift right SHR
Decrement DEC Complement COM Logical shift left SHL
Add ADD AND AND Arithmetic shift right SHRA
Subtract SUB OR OR Arithmetic shift left SHLA
Multiply MUL Exclusive-OR XOR Rotate right ROR
Divide DIV Clear carry CLRC Rotate left ROL
Add with carry ADDC Set carry SETC Rotate right through carry RORC
Subtract with borrow SUBB Complement carry COMC Rotate left through carry ROLC
Negate (2’s complement) NEG Enable interrupt EI
Disable interrupt DI
Section - 9
Program Control
A program control type of instruction, when executed, may change the address value in the
program counter and cause the flow of control to be altered.
The change in value of the program counter as a result of the execution of a program control
instruction causes a break in the sequence of instruction execution.
Name Mnemonic
Branch BUN
Jump JMP
Skip SKP
Call CALL
Return RET
Compare (by subtraction) CMP
Test (by ANDing) TST
Status Bit Conditions
A B Bit C (carry) is set to 1 if the end
8 8
carry C8 is 1. It is cleared to 0 if the
𝐶7 carry is 0.
8-bit ALU
𝐶8 Bit S (sign) is set to 1 if the highest-
V Z S C order bit F7 is 1. It is set to 0 if the
𝐹7 − 𝐹0 bit is 0.
Bit Z (zero) is set to 1 if the output is
𝐹7 zero and Z = 0 if the output is not
zero.
Bit V (overflow) is set to 1 if the
exclusive-OR of the last two carries
Check for zero output
is equal to 1, and cleared to 0
otherwise. This is the condition for
8
an overflow when negative numbers
are in 2’s complement.
Output F
Conditional Branch Instructions
Mnemonic Branch Condition Tested Mnemonic Branch Condition Tested
Condition Condition
BZ Branch if zero Z=1 BLO Branch if lower A<B
BNZ Branch if not zero Z=0 BLOE Branch if lower or equal A≤B
BC Branch if carry C=1 BE Branch if equal A=B
BNC Branch if no carry C=0 BNE Branch if not equal A≠B
BP Branch if plus S=0 Signed compare conditions (A – B)
BM Branch if minus S=1 BGT Branch if greater than A>B
BV Branch if overflow V=1 BGE Branch if greater or equal A ≥ B
BNV Branch if no overflow V=0 BLT Branch if less than A<B
Unsigned compare conditions (A – B) BLE Branch if less or equal A≤B
BHI Branch if higher A>B BE Branch if equal A=B
BHE Branch if higher or equal A ≥ B BNE Branch if not equal A≠B
Program Interrupt
The interrupt procedure is, in principle, quite similar to a subroutine call except for three
variations:
1. The interrupt is usually initiated by an internal or external signal rather than from the execution of an
instruction
2. The address of the interrupt service program is determined by the hardware rather than from the address
field of an instruction
3. An interrupt procedure usually stores all the information necessary to define the state of the CPU rather than
storing only the program counter.
After a program has been interrupted and the service routine has been executed, the CPU
must return to exactly the same state that it was when the interrupt occurred. Only if this
happens will the interrupted program be able to resume exactly as if nothing had happened.
The state of the CPU at the end of the execute cycle (when the interrupt is recognized) is
determined from:
1. The content of the program counter
2. The content of all processor registers
3. The content of certain status conditions
Types of interrupts
There are three major types of interrupts that cause a break in the normal execution of a
program. They can be classified as:
1. External interrupts
2. Internal interrupts
3. Software interrupts
1. External Interrupt
External interrupts come from
Input-output (I/O) devices
Timing device
Circuit monitoring the power supply
Any other external source
Examples that cause external interrupts are
I/O device requesting transfer of data
I/O device finished transfer of data
Elapsed time of an event
Power failure
External interrupts are asynchronous.
External interrupts depend on external conditions that are independent of the program being
executed at the time.
2. Internal interrupts (Traps)
Internal interrupts arise from
Illegal or erroneous use of an instruction or data.
Examples of interrupts caused by internal error conditions like
Register overflow
Attempt to divide by zero
invalid operation code
stack overflow
protection violation.
These error conditions usually occur as a result of a premature termination of the instruction
execution.
Internal interrupts are synchronous with the program. If the program is rerun, the internal
interrupts will occur in the same place each time.
3. Software interrupts
A software interrupt is a special call instruction that behaves like an interrupt rather than a
subroutine call.
The most common use of software interrupt is associated with a supervisor call instruction.
This instruction provides means for switching from a CPU user mode to the supervisor mode.
When an input or output transfer is required, the supervisor mode is requested by means of a
supervisor call instruction. This instruction causes a software interrupt that stores the old CPU
state and brings in a new PSW that belongs to the supervisor mode.
The calling program must pass information to the operating system in order to specify the
particular task requested.
Section - 10
Reduced Instruction Set Computer (RISC)
Characteristics of RISC are as follows:
Relatively few instructions
Relatively few addressing modes
Memory access limited to load and store instructions
All operations done within the registers of the CPU
Fixed-length, easily decoded instruction format
Single-cycle instruction execution
Hardwired rather than microprogrammed control
A relatively large number of registers in the processor unit
Use of overlapped register windows to speed-up procedure call and return
Efficient instruction pipeline
Compiler support for efficient translation of high-level language programs into machine language programs
Overlapped Register Window
R15
Common to D and A
A characteristic of some
R10 RISC processors is their
R73
Local to D use of overlapped
R64 register windows to
R63
Common to C and D provide the passing of
R58
Proc D R57 parameters and avoid
Local to C the need for saving and
R48
R47
Common to B and C
restoring register
Window size = L + 2C + G R42 values.
Proc C R41
Register file = (L + C) W + G Local to B Each procedure call
R32
R31 results in the allocation
Common to A and B
R26 of a new window
R9
Common to all Proc B R25
Local to A
consisting of a set of
procedures R16 registers from the
R0 R15
Global
Common to A and D register file for use by
R10 the new procedure.
register Proc A
s
Overlapped Register Window
Windows for adjacent procedures have overlapping registers that are shared to provide the
passing of parameters and results.
Suppose that procedure A calls procedure B.
Registers R26 through R31 are common to both procedures, and therefore procedure A stores
the parameters for procedure B in these registers.
Procedure B uses local registers R32 through R41 for local variable storage.
If procedure B calls procedure C, it will pass the parameters through registers R42 through
R47.
When procedure B is ready to return at the end of its computation, the program stores results
of the computation in registers R26 through R31 and transfers back to the register window of
procedure A.
Note that registers R10 through R15 are common to procedures A and D because the four
windows have a circular organization with A being adjacent to D.
Overlapped Register Window