Module 3
Module 3
1
Name of Institution
Module – 3
Central Processing Unit
2
Central Processing Unit
Name of Institution
Register Set
Control Unit
Arithmetic Logic
Unit (ALU)
1. Register set stores the intermediate data used during the execution
of the instructions.
2. Arithmetic Logic Unit (ALU) performs the required
microoperations for executing the instructions.
3. Control unit supervises the transfer of information among the
registers and instructs the ALU as to which operation to perform. 4
General Register Organization
Name of Institution
Block Diagram 6
General Register Organization
Name of Institution
Example:
To perform the operation: R1← R2 + R3
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.
9
Control Word Name of Institution
Example of Microoperation:
The subtract microoperation given by the statement
R1← R2 - R3
00101
13
Control Word Name of Institution
14
Stack Organization Name of Institution
Stack is a storage device that stores information in such a
manner that the last item stored is the first item retrieved.
Based on LIFO – Last-in-first-out.
✓ Stack in digital computers is a group of memory
locations with a address register that can count.
✓ The register that holds the address of top element of the
stack is called a Stack Pointer (SP).
The two operations of a stack are:
Push : Inserts an item on top of stack
Pop : Deletes an item from top of stack 15
Register Stack Name of Institution
Stack pointer
contains 6 bits
∴ 26 = 64 address
Block diagram of
64-word stack
17
Memory Stack Name of Institution
Memory Stack:
Stack depth is flexible.
Exist stand-alone or can be
implemented in RAM.
✓ Uses processor register as SP.
19
Instruction Formats Name of Institution
Computers usually have a variety of instruction code
formats.
The function of the control unit within the CPU is
to interpret each instruction code and provide the
necessary control functions needed to process the
instruction.
The format of an instruction is usually represented
by a rectangular box.
Instructions are a series of bits (0 and 1). The bits
of the instruction are divided into groups called fields. 20
Instruction Formats Name of Institution
The most common fields found in instruction formats
are:
1. An operation code field that specifies the operation
to be performed.
2. An address field that designate a memory address or
a processor register.
3. A mode field that specifies the way the operand or the
effective address is determined.
21
Instruction Formats Name of Institution
Computers may have instructions of several different
lengths containing varying number of address.
The number of address fields in the instruction
format of a computer depends upon the international
organization of its registers.
Types of CPU Organizations:
1. Single Accumulator Organization
2. General Register Organization
3. Stack Organization 22
Instruction Formats Name of Institution
1. Single Accumulator Organization
This type of computer uses one address field.
ADD X AC ← AC+M[X]
2. General Register Organization
It uses two or three address fields in their
instruction format.
ADD R1, X R1 ← R1+M[X]
3. Stack Organization
Stack computer consists of op-code only with no
address.
e.g. - ADD
It can have PUSH or POP instructions that needs an
address field.
e.g. – PUSH X 23
Instruction Formats Name of Institution
1. Zero-Address Instructions
2. One-Address Instructions
3. Two-Address Instructions
4. Three-Address Instructions
24
Instruction Formats Name of Institution
Three-Address Instructions
Computers with three-address instruction formats
can use each address field to specify either a processor
register or a memory operand.
To evaluate a arithmetic expression X=(A+B)(C+D)
the following are the register transfer
operation of each instruction.
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
Advantage Disadvantage
results in short programs when Binary coded instructions require too
evaluating arithmetic expressions many bits to specify three addresses
25
Instruction Formats Name of Institution
Two-Address Instructions
Most common in commercial computers.
Here, each address field can specify either a processor
register or a memory word.
The program to evaluate X = (A + B) (C + D)
26
Instruction Formats Name of Institution
One-Address Instructions
It uses an implied accumulator (AC) register for all data
manipulation. The program to evaluate: X = (A + B) (C + D)
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
29
Addressing Modes Name of Institution
▪ Implied Mode
▪ Immediate Mode
▪ Register mode
▪ Register Indirect mode
▪ Autoincrement or Autodecrement Mode
▪ Direct Address mode
▪ Indirect Address mode
▪ Relative Address mode
▪ Indexed Address mode
▪ Base Register Addressing mode
30
Addressing Modes Name of Institution
Implied mode
Operand is specified implicitly in the definition
of instructions.
Used for zero-address or one-address instruction
Example: Complement AC, Increment AC,
Immediate mode
• Operand is part of instruction
• Operand = address field
e.g. ADD 5
—Add 5 to contents of accumulator
—5 is operand
• No memory reference to fetch data
32
Addressing Modes Name of Institution
Register mode
Operand is present in register named in address field.
Example : LD R1 AC ← R1
Instruction Registers
• EA = R
Operand
• Limited number of registers
• Very small address field needed
—Shorter instructions
—Faster instruction fetch
• No memory access
• Very fast execution
33
Addressing Modes Name of Institution
34
Addressing Modes Name of Institution
35
Addressing Modes Name of Institution
36
Addressing Modes Name of Institution
37
Addressing Modes Name of Institution
Effective Address =
Content of Program Counter +
Address part of the instruction
Effective Address
= Content of Index Register +
39
Address part of the instruction
Addressing Modes Name of Institution
Effective Address
= Content of Base Register +
Address part of the instruction 40
Data Transfer and Manipulation
Name of Institution
41
Data Transfer Instructions
Name of Institution
1. Arithmetic instructions:
The four basic arithmetic operations are addition,
subtraction, multiplication and division.
Arithmetic instructions may specify fixed-point
or floating-point data, binary or decimal data, single-
precision or double-precision data.
44
Data Manipulation Instructions
Name of Institution
Name Mnemonic
Increment INC
Decrement DEC
Add ADD
Subtract SUB
Multiply MUL
Divide DIV
Add with carry ADDC
Subtract with borrow SUBB
Negate(2’s complement) NEG
45
Data Manipulation Instructions
Name of Institution
3. Shift instructions:
There are four types of shift instructions:
▪ Logical shift instructions
▪ Arithmetic shifts instructions
▪ Rotate instructions
▪ Rotate through carry instruction
48
Data Manipulation Instructions
Name Mnemonic
Name of Institution
49
Program Control InstructionsName of Institution
23 10111 Multiplicand
19 x 10011 Multiplier
10111
10111
00000
00000
10111____
437 110110101 Product
58
Computer Arithmetic Name of Institution
63
Computer ArithmeticName of Institution
Floating-Point Arithmetic Operations
Floating-point arithmetic is a method for representing real
numbers in a way that can support a wide range of values.
The term "floating-point" refers to the fact that a
number's decimal point can “float”.
This flexibility allows for the representation of very large and
very small numbers needed for scientific computations and
where the precision of calculations is essential.
There are two part of a floating-point number in a
computer - a mantissa m and an exponent e.
± 𝑚 × 𝑟𝑒
For example: The decimal number 537.25 is represented in a
register with m = 53725 and e = 3 and is interpreted to
represent the floating-point number.
0.53725 × 103 64
Computer ArithmeticName of Institution
Normalization: A floating-point number is said to be
normalized, if the most significant digit of the mantissa in
non-zero.
It can be done by shifting the mantissa.
Example: 350 normalized
0035 not normalized
Registers for
Floating Point
Arithmetic ops.
65
Computer ArithmeticName of Institution
Arithmetic operations with floating-point numbers
Addition
Subtraction
Multiplication
Subtraction
66
Computer ArithmeticName of Institution
1. Check for zeros:
Registers: AC & BR
AC = 0.583123 × 103
BR = 0.000012 × 103 one bit lost (preferable)
Case 2: +3 to -1
3-(-1)=4 Shift left operation
0.583123 × 103 → 0.23000 × 10−1
69
Computer ArithmeticName of Institution
Another example
Addition: 0.532 × 103
0.712 × 103
𝟏. 244 × 103
This is overflow
1. Perform ShR 2. Increment the exponent
= 0.1244 × 104
It is normalized as MSB=1
BR = 0.12 × 104
QR = 0.23 × 103
71
Computer ArithmeticName of Institution
For BR = 0.12 × 104
QR = 0.23 × 103
Add the exponents: b=4, q=3
a=b+q=3+4=7
72
Computer ArithmeticName of Institution
Floating point Division
It can be divided into 4 steps:
1. Check for zeros
2. Initialize registers and evaluate the sign
3. Align the dividend
4. Subtract the exponent
5. Divide the Mantissa
BR = 1.249 × 104
QR = 0.62 × 103
Check for zeros:
𝐴𝐶 𝐴𝐶
1. 𝐵𝑅 = 0 𝐵𝑅
=
0
𝐴𝐶 0
2. 𝐵𝑅 ≠ 0 , 𝐴𝐶 = 0 𝐵𝑅
=
𝐵𝑅
3. 𝐵𝑅 ≠ 0 , 𝐴𝐶 ≠ 0 , then proceed to step 2 73
Computer ArithmeticName of Institution
Initialize registers and evaluate the sign
a= b XOR q
Thank You!
75