Central Processing Unit
Central Processing Unit
UNIT - IV
CONTENT
There are two types of stack organization that are used in computer
architecture:
Register stack: It is built using a register.
Memory stack: It is the logical part of memory allocated as the stack. The
logically partitioned part of RAM is used to implement the stack.
REGISTER STACK ORGANIZATION
A stack can be organized as a collection of a finite number of
memory words or registers.
In the figure, there are 64 registers used to make a register
stack. The numbers 0,1,2,3,….. 63 denote the address of
different registers (Binary address representation is 000000 …
111111).
SP is a pointer that points to the top of the stack i.e. it
currently points to the item at the top (in this figure SP
contains a 6-bit address).
In a 64-word stack, the stack pointer contains 6 bits because
26=64.
Since SP has only 6 bits, it cannot exceed a number greater
than 63(111111 in binary). When 63 is incremented by 1 the
result is 0 since 111111+1=1000000, but SP can
accommodate only the six least significant bits → SP points to
the 000000 address register which implies the stack is full.
REGISTER STACK ORGANIZATION
The upper limit register and lower limit register are used to check
the stack’s overflow (Full) and underflow (Empty).
Most computers do not provide hardware to check stack overflow (full
stack) or underflow (empty stack). It must be done in the software
REVERSE POLISH NOTATION
Introduction
The stack organization is very effective in evaluating the arithmetic expression.
Types of Notations
Infix notation (Eg. A+B)
Used by general
register
Prefix notation or Polish notation (Eg. +AB)
organization
Postfix notations or Reverse Polish Notation (Eg. Used
AB+) by stack
organization
REVERSE POLISH NOTATION
Reverse Polish notation (RPN) is a method for conveying mathematical expressions without the
use of separators such as brackets and parentheses.
In this notation, the operators follow their operands, hence removing the need for the brackets
to define evaluation priority.
The operation is read from left to right but execution is done every time an operator is reached.
This notation is suited for computers and calculators since there are fewer characters to
track and fewer operations to execute.
Reverse Polish notation is also known as postfix notation
Example:
(A+B)*(C*(D+E)+F)
RPN is AB+CDE+*F+*
EVALUATION OF ARITHMETIC EXPRESSION
Rules
In RPN, the numbers and operators are listed one after another, and an operator
always acts on the most recent number in the list.
The numbers can be thought of as forming a stack, and the most recent number
goes on the top of the stack.
An operator takes the appropriate number of arguments from the top of the stack
and replaces them with the result of the operation.
EVALUATION OF ARITHMETIC EXPRESSION
Stack representation
3 4 * 5 6 * +
4 5 5 30
3 3 12 12 12 12 42
PROCESSOR ORGANIZATION
Any of the registers can be used as the source or destination for computer operations
Stack organization
For example, an OR instruction will pop the two top elements from the stack, do a logical OR
on them, and push the result on the stack
3. INSTRUCTION FORMAT
INSTRUCTION FORMAT
In computer architecture, the instruction format is defined as a standard machine
instruction format that can be directly decoded and executed by the central processing
unit ( CPU ).
The instruction format is simply a sequence of bits ( binary 0 or 1 ) contained in a
machine instruction that defines the layout of the instruction.
The machine instruction contains the number of bits (patterns of 0 and 1 ). These bits are
grouped together and called fields.
Each field of the machine instruction provides specific information to the CPU regarding
the operation to be performed and the location of the data.
An instruction is of various lengths depending upon the number of addresses
it contains. Generally, CPU organizations are of three types on the basis of the number
of address fields:
1. Single Accumulator organization
2. General register organization`
3. Stack organization
CPU ORGANIZATION
All the operations on a system are performed with an implied accumulator register.
The instruction format in this type of computer uses one address field.
language instruction ‘ADD.’ Where X is the operand’s address, the ADD instruction
results in the operation.
AC ← AC + M[X].
AC is the accumulator register, and M[X] symbolizes the memory word located at
address X.
CPU ORGANIZATION
The general register type computers employ two or three address fields in their
This instruction has two address fields: register R1 and memory address X.
CPU ORGANIZATION
3. Stack Organization
A computer with a stack organization has PUSH and POP instructions that require an
address field. Hence, the instruction PUSH X pushes the word at address X to the top
of the stack. The stack pointer updates automatically.
address field as the operation is performed on the two items on the top of the
stack.
INSTRUCTION FORMAT REPRESENTATION
Instruction format is a sequence of bits contained int the machine instruction that
defines the layout of an instruction.
INSTRUCTION FORMAT TYPE
The set of instructions that manages the operation codes is called the format
of instruction. The design of bits in instruction is supported by the format of
instruction.
The length of instruction is generally preserved in multiples of character, which is
8 bits. Depending upon the number of addresses, the format of instruction is of
variable length.
Types of instruction format include:
The operation field of an instruction specifies the operation to be performed. This operation
will be executed on some data which is stored in computer registers or the main memory.
Addressing modes define the rules and mechanisms by which the processor
calculates the effective memory address or operand location for data operations.
The way any operand is selected during the program execution is dependent on the
addressing mode of the instruction. The purpose of using addressing modes is as follows:
8 Indirect Addressing
Modes
9 Displacement Addressing
Modes
10 Relative Addressing
Modes
11 Indexed Addressing
Modes
12 Base Register
Addressing Modes
13 Stack Addressing Modes
APPLICATIONS OF ADDRESSING MODES
Program sizes can be reduced drastically as the code can be compacted which
Addressing modes give you the flexibility to use different ways of specifying
and mode, and the second word specifies the address part.
PC has the value 200 for fetching this instruction. The content
With different Addressing Modes: Eight addressing modes for Load instruction
DATA MANIPULATION INSTRUCTIONS
the Computer.
1. Arithmetic instruction
3. Shift instructions
1. ARITHMETIC INSTRUCTIONS
Arithmetic instructions
Name Mnemonic
include increment,
Increment INC
decrement, add, subtract,
Decrement DEC
multiply, divide, add with
Add ADD
Carry, subtract with Borrow,
Subtract SUB
and negate that is (2’s) two's
Multiply MUL
complement. If there’s a
Divide DIV
negative number, it is
Add with carry ADDC
considered as negate (so
Subtract with
two's complement). SUBB
borrow
2. LOGICAL AND BIT MANIPULATION INSTRUCTIONS
Name Mnemonic
Clear CLR
These logical instructions Complement COM
consider each operand bit AND AND
individually and treat it as a
OR OR
Boolean variable.
Exclusive-OR XOR
Basically, logical instructions help Clear carry CLRC
Enable Interrupt EI
Disable Interrupt DI
3. SHIFT INSTRUCTIONS
Shift instructions allow the bits of a memory byte or
There are basically two types of shift instructions — Logical Shift Left SHL
Arithmetic shifts consider the contents of the memory Arithmetic Shift Left SHLA
byte or register to be a signed number. So, when the Rotate Right ROR
shift is made, the number is arithmetically divided by
Rotate Left ROL
two (right shift) or multiplied by two (left shift).
Rotate Right through
RORC
Logical shifts consider the contents of the register or carry
memory byte to be just a bit pattern when the shift is Rotate Left through
ROLC
made. carry
6. PROGRAM CONTROL
PROGRAM CONTROL INSTRUCTIONS
It is the instruction that alters the sequence of the program's execution, which means it changes
the value of the program counter, due to which the execution of the program changes.
Features:
These instructions cause a change in the sequence of the execution of the instruction.
Flag-Control Instructions.
Control Flow and the Jump Instructions include jumps, calls, returns, interrupts, and machine control
instructions.
To check different conditions for branching instructions like CMP (compare) or TEST
can be used. Certain status bit conditions are set as a result of these operations.
V Z S C
Status bits mean that the value will be either 0 or 1 as it is a bit. We have four status bits:
"V" stands for Overflow: based on certain bits, i.e., if extra bits are generated into our operation.
"Z" stands for Zero: If the output of the ALU(Arithmetic Logic Unit) is 0, then the Z flag is set to 1, otherwise, it is set to 0.
"S" stands for the Sign bit: If the number is positive, the Sign(S) flag is 0, and if the number is negative, the Sign flag is 1.
"C" stands for Carry: if the output of the ALU operation generates Carry, then C is set to 1, else C is set to 0.
STATUS BIT CONDITIONS/ FLAG, PROCESSOR STATUS WORD
1. CONDITIONAL BRANCH INSTRUCTIONS
When called, branches to 1st line of the subroutine and at the end, returned to the main program.
Different names for the instruction that transfers program control to a subroutine
Call subroutine
Jump to subroutine
Branch to a subroutine
Branch to the beginning of the Subroutine - Same as the Branch or Conditional Branch.
Save the Return Address to get the address of the location in the Calling Program upon
In a processor Register
In Memory Stack
3. PROGRAM INTERRUPT
Types of Interrupts:
External interrupts
Internal interrupts
Software interrupts
3. PROGRAM INTERRUPT
3. INTERRUPT PROCEDURE
Step 1 − First device issues interrupt to CPU.
Step 2 − Then, the CPU finishes the execution of the current instruction.
Step 4 − CPU saves program status word onto the control stack.
Step 5 − CPU loads the location of the interrupt handler into the PC
register.
Step 6 − Save the contents of all registers from the control stack into
memory.
RISC processors use one clock per cycle (CPI) to execute each instruction in a
computer. Each CPI also comprises the methods for fetching, decoding, and
executing computer instructions.
Multiple registers in RISC processors allow them to hold instructions, reply fast to the
The RISC processors use the pipelining technique to execute multiple parts or stages
RISC has a simple addressing mode and fixed instruction length for the pipeline
execution.
CISC chips are relatively slower than RISC chips but use little
instructions. CISC
Architecture
Examples of CISC processors are AMD, Intel x86, and the
System/360.
FEATURES OF CISC PROCESSOR
CISC may take longer than a single clock cycle to execute the code.