Central Processing Unit-1
Central Processing Unit-1
(COA)
GTU # 3140707
UNIT-3
Central Processing Unit
Dr.K.Arun Kumar
Outline
Looping
• 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)
General Register Organization
Clock Input
R1
R2
R3
R4
R5
R6
R7
Load
(7 lines) SEL MUX - A MUX - B SEL
A B
3x8 A - bus B - bus
decoder
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] B 2
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
PUSH Operation Address
PC Program 1000
SP ← SP - 1 (instructions)
AR Data 2000
M[SP] ← (operands)
DR 3000
POP Operation Stack
3997
DR ←
SP 3998
M[SP]
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* AB * CD * +
D 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 * +
Instruction format
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.
400 700
AC 800
500
600 900
325
702
300
800
Data transfer and manipulation
Data transfer instructions
Data transfer instructions move data from one place in the computer to another without
changing the data content.
The most common transfers are between memory and processor registers, between processor
registers and input or output, and between the processor registers themselves.
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
𝐹7 is zero and Z = 0 if the output is not
zero.
Bit V (overflow) is set to 1 if the
Check for zero output exclusive-OR of the last two carries
is equal to 1, and cleared to 0
8
otherwise. This is the condition for
an overflow when negative numbers
Output F are in 2’s complement.
Conditional Branch Instructions
Mnemoni Branch Condition Tested Mnemoni Branch Condition Tested
c Condition c 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 A≥B
BNV Branch if no overflow V=0 equal
Unsigned compare conditions (A – B) BLT Branch if less than A<B
BHI Branch if higher A>B BLE Branch if less or equal A≤B
BHE Branch if higher or A≥B BE Branch if equal A=B
equal 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 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.
Reduced Instruction Set
Computer (RISC)
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.
Complex Instruction Set
Computer (CISC)
Complex Instruction Set Computer (CISC)
Characteristics of CISC are as follows:
A larger number of instructions – typically from 100 to 250 instructions
Some instructions that perform specialized tasks and are used infrequently
A large variety of addressing modes – typically from 5 to 20 different modes
Variable-length instruction formats
Instructions that manipulate operands in memory
END OF UNIT-III
FIRST HALF