Course Name: Computer Organization and Architecture Course Code: AI553
Course Name: Computer Organization and Architecture Course Code: AI553
Control unit
Functions of this unit are
It is responsible for controlling the transfer of data and
instructions among other units of a computer.
It manages and coordinates all the units of the computer.
It obtains the instructions from the memory, interprets them,
and directs the operation of the computer.
It communicates with Input/output devices for transfer of
data or results from storage.
It does not process or store data.
BASIC OPERATIONAL CONCEPTS
Connection between the processor and Memory
17
BASIC OPERATIONAL CONCEPTS
◻ The contents of PC(i.e. address) are transferred to the MAR & control-unit
issues Read signal to memory. • After certain amount of elapsed time, the first
instruction is read out of memory and placed into MDR
◻ . Next, the contents of MDR are transferred to IR. At this point, the instruction
can be decoded & executed
◻ . To fetch an operand, it's address is placed into MAR & control-unit issues Read
signal. As a result, the operand is transferred from memory into MDR, and then
it is transferred from MDR to ALU.
◻ Likewise required number of operands is fetched into processor.
◻ Finally, ALU performs the desired operation. • If the result of this operation is
to be stored in the memory, then the result is sent to the MDR.
◻ The address of the location where the result is to be stored is sent to the MAR
and a Write cycle is initiated.
◻ At some point during execution, contents of PC are incremented to point to
next instruction in the program. [The instruction is a combination of opcode and
operand].
1. **Program Counter (PC):**
- Contains the memory address of the instruction to be executed.
The operational steps described in the passage can be related to the fetch-decode-execute cycle, which is a fundamental process in the operation of a
CPU. Here's a◻more .To fetch
detailed an operand,
breakdown it'ssteps:
of the operational address is placed into MAR & control-unit issues Read
1. **Fetch:** signal. As a result, the operand is transferred from memory into MDR, and then
it is transferred
- The Program Counter from address
(PC) contains the memory MDR oftotheALU.next instruction to be executed.
- The contents of the PC are released to the internal bus and sent to the Memory Address Register (MAR).
◻ Likewise required number of operands is fetched into processor.
- The MAR holds the address, and this address is used to fetch the instruction from the main memory.
- The fetched instruction is placed into the Memory Data Register (MDR).
2. **Decode:**◻ Finally, ALU performs the desired operation. • If the result of this operation is
- The content of theto MDR,
be stored
which now inholds
- The IR contains the instruction being executed.
thethe memory, then
fetched instruction, the result
is transferred is sent Register
to the Instruction to the(IR).
MDR.
and the operands The address of the location where the result is to be stored is sent to the MAR
- Before execution, the instruction needs to be decoded. The decoding process interprets the instruction to determine the operation to be performed
◻ involved.
3. **Execute:**
and a Write cycle is initiated.
Atan some
arithmetic point
operation,during execution,
- After decoding, the CPU performs the actual operation specified by the instruction.
◻
- If the instruction is the ALU (Arithmetic contents
Logic Unit) of inPC
may be involved areoutincremented
carrying the computation. to point to
- If the instructionnext
involvesinstruction
data transfer, the indata
themayprogram. [The
be moved between instruction
registers, the memory,isoraother
combination of opcode
components as directed and
by the instruction.
4. **Update:** operand].
- The Program Counter (PC) is updated to point to the next instruction in memory.
- The cycle then repeats, starting with the fetch of the next instruction.
This series of steps, known as the fetch-decode-execute cycle, is repeated continuously as long as the computer is running. It is a fundamental process
that allows the CPU to fetch instructions from memory, execute them, and move on to the next instruction in a sequential manner, forming the basis for
the execution of computer programs.
Bus Structure
There are many ways to connect different parts
inside a computer together.
A group of lines that serves as a connecting path
for several devices is called a bus.
Address/data/control
BUS STRUCTURE
◻ A bus is a group of lines that serves as a connecting path for several devices.
◻ Bus must have lines for data transfer, address & control purposes. • Because the bus can
be used for only one transfer at a time, only 2 units can actively use the bus at any given
time.
◻ Bus control lines are used to arbitrate multiple requests for use of the bus.
◻ Main advantage of single bus: Low cost and flexibility for attaching peripheral devices.
◻ Systems that contain multiple buses achieve more concurrency in operations by allowing 2
or more transfers to be carried out at the same time.
◻ Advantage: better performance.
◻ Disadvantage: increased cost.
◻ The devices connected to a bus vary widely in their speed of operation.
◻ To synchronize their operational speed, the approach is to include buffer registers with the
devices to hold the information during transfers. Buffer registers prevent a high-speed
processor from being locked to a slow I/O device during a sequence of data transfers.
Bus Structure
Single-bus
Bus Structure
Speed Issue
Different devices have different transfer/operate speed.
o Keyboard, printers are slow
o Magnetic or optical disk are fast
o Memory and processor are faster
If the speed of bus is bounded by the slowest device
connected to it, the efficiency will be very low.
How to solve this?
A common approach – use buffers.
Performance
⮚ Compiler design
Performance – Hardware design
Pipelining
Instructions are not necessarily executed one after
another.
Clock Rate
Increase clock rate
⮚ Improve the integrated-circuit (IC) technology to make
the circuits faster
⮚ Reduce the amount of processing done in one basic
step (however, this may increase the number of basic
steps needed)
Performance – Instruction set
◻ T is difficult to compute
METRICS
Processor clock
Basic performance equation
Pipelining & super scalar operation
Clock rate
Instruction set CISC & RISC
Compiler
Performance measurement
Number, Arithmetic Operations, and
Characters
Let us learn
◻ Binary number representation
◻ Arithmetic operation on these number
◻ Character representation
Number, Arithmetic Operations, and
Characters
◻ Computers are built using logic circuits that operate on
information represented by two values 0 and 1.
◻ The bit of information stands for binary digit
◻ Represent number string of bits called binary
number
◻ Represent Text character string of bits called
character code
Number, Arithmetic Operations, and
Characters
◻ Integer number are represented in two forms
Signed integer
Unsigned integer
◻ Unsigned integer number represent positive numbers.
◻ Computer does not have provision to represent
negative sign, so various techniques are used
Number, Arithmetic Operations, and
Characters
◻ Computers are built using logic circuits that operate on
information represented by two values 0 and 1.
◻ The bit of information stands for binary digit
◻ Represent number string of bits called binary
number
◻ Represent Text character string of bits called
character code
Number, Arithmetic Operations, and
Characters
Number representation
◻ Various techniques to represent signed integer number
are
o Sign and magnitude
o One’s complement
o Two’s complement
Number, Arithmetic Operations, and
Characters
◻ Integer number are represented in two forms
o Signed integer
o Unsigned integer
◻ Unsigned integer number represent positive numbers.
◻ Computer does not have provision to represent
negative sign, so various techniques are used
Number, Arithmetic Operations, and
Characters
Number, Arithmetic Operations, and
Characters
◻ Assumptions:
4-bit machine word
16 different values can be represented
Roughly half are positive, half are negative
Number, Arithmetic Operations, and
Characters
Sign-and-magnitude
system
Plus(+) sign to represent positive number and Minus(-) sign to represent
negative number
Positive number and Negative number are represented with binary digits.
The leftmost bit(sign bit) in the number represent sign of the number.
The remaining bits represent magnitude of number
Signed magnitude format for 4-bit signed number
Sign Magnitude
Sign-and-magnitude
system
b3 b2 b1 b0
+0 0 0 0 0
-0 1 0 0 0
Sign-and-magnitude
system
b3 b2 b1 b0
+1 0 0 0 1
-1 1 0 0 1
Sign-and-magnitude
system
b3 b2 b1 b0
5
2
+5 0 1 0 1 2 2 1
-5 1 1 0 1 1
0
Sign-and-magnitude
system
2 6
b3 b2 b1 b0
2 3 0
+6 0 1 1 0 1
1
-6 1 1 1 0
Sign-and-magnitude
system
7
b3 b2 b1 b0 2
2 3 1
+7 0 1 1 1
1 1
-7 1 1 1 1
Sign-and-magnitude
system
For addition and subtraction, it is necessary to consider signs of both the number and their relative
magnitude in order to carry out the required arithmetic operation
There are two representation of zero(0)
+0 0000
-0 1000
Due to this, it is difficult to test for zero operation frequently
performed by computer
1's complement system
b3 b2 b1 b0
+0 0 0 0 0
-0 1 1 1 1
1's complement system
b3 b2 b1 b0
+1 0 0 0 1
-1 1 1 1 0
1's complement system
b3 b2 b1 b0
+5 0 1 0 1
-5 1 0 1 0
5
2
2 2 1
0
1
2's complement system
C 1
+2 0 0 1 0
1’s 1 1 0 1
1
-2 1 1 1 0
5
2
2's complement system
2 2 1
0
1
C
+5 0 1 0 1
1’s 1 0 1 0
1
-5 1 0 1 1
7
2
2's complement system
2 3 1
1 1
C
+7 0 1 1 1
1’s 1 0 0 0
1
-7 1 0 0 1
2's complement system
C 1 1 1 1
+0 0 0 0 0
1’s 1 1 1 1
1
-0 0 0 0 0
2's complement system
Advantages
Here One representation for +0 and -
0
Here -8 is representable
sum 0
Number, Arithmetic Operations, and
Characters
◻ Various techniques
o Sign and magnitude
o One’s complement
o Two’s complement
◻ They differ in the way we
represent negative numbers
To understand 2’s complement arithmetic
Consider addition
modulo N(mod N)
A Graphical device of addition
mod N of positive integers is a
circle with N values ( 0 to N-
1)along its perimeter
Use this device to compute
(a+b) mod N
To understand 2’s complement arithmetic
Consider the case N=16
(a + b) mod N
15
(7 +4) mod 16
14
= 11
13 3
Locate 7 on the circle and then
12 4 move 4 units in the clockwise
direction to arrive at the
11 5
answer 11
10 6
9 7
8
To understand 2’s complement arithmetic
Consider the case N=16
(a + b) mod N
15
(9 +14) mod 16
14
23 mod 16
13
=7
3
Two rules for addition and subtraction of n-bit signed numbers using the 2's
complement representation system
Rule 1:
To Add two numbers, add their n-bits and ignore the carry-out signal from the
MSB position.
Result will be algebraically correct, if it lies in the range -2n-1 to +2n-1-1.
Rule 2:
To Subtract two numbers X and Y (that is to perform X-Y), take the 2's
complement of Y and then add it to X as in rule 1.
Rule 1:
To Add two numbers, add their n-bits and ignore the carry-out
signal from the MSB position.
Result will be algebraically correct, if it lies in the range -2n-1 to
+2n-1-1.
C 1
+2 0 0 1 0
+3 0 0 1 1
+5 0 1 0 1
Addition rule
2's complement system
C
+4 0 1 0 0
-6 1 0 1 0
-2 1 1 1 0
Addition rule
2's complement system
C 1 1 1
-5 1 0 1 1
-2 1 1 1 0
s -7 1 0 0 1
SUBTRACTION OF SIGNED NUMBERS
Rule 2:
To Subtract two numbers X and Y (that is to perform
X-Y), take the 2's complement of Y and then add it to X
as in rule 1.
Result will be algebraically correct, if it lies in the range
-2n-1 to +2n-1-1.
Y +1 1 1 1 1 C
X-Y -8 1 0 0 0 Y +1 0 0 0 1
1’ 1 1 1 0
s
1
1 1 1 1
Subtraction rule
2's complement system
1
X +2 0 0 1 0
Y -3 0 0 1 1 C
X-Y +5 0 1 0 1 Y 1 1 0 1
1’ 0 0 1 0
s
1
0 0 1 1
OVERFLOW IN INTEGER ARITHMETIC
What is Memory
It is a storage unit, a place to hold data and instruction.
Memory Location and Addresses
Memory Organisation
Memory consist of
many millions of
storage cells.
Each cell can store 1-bit
information having
value (0 or 1)
Memory organized as
group of n-bits
Memory Location and Addresses
Group of n-bits is
referred as word
n is called word length
The word length of 8 bit
is known as byte
Word length can range
from 16 to 64bits,
simple called word.
Memory Location and Addresses
Memory Location
Memory is divided into
multiple small parts, of
fixed size and capable of
holding information.
Memory Address
ô Each memory location is
uniquely identified by a
BINARY ADDRESS(HEXA
VALUE).
Memory Location and Addresses
Memory Address
If 2k addresses constitute the address space of computer,
then memory can have up to 2k addressable locations.
Example
k= 10 , 210 = 1,024(1K kilo) locations
k= 20 , 220 = 1,048,576(1M mega) locations
k= 24 , 224 = 16,777,216(16M mega) locations
k= 30 , 230 = 1G (giga) locations
k= 32 , 232 = 4G (giga) locations
k= 40 , 240 = 1T(tera) locations
Memory Location and Addresses
Big Endian
The MSB of the data is
placed at the byte with
the lowest address.
Little Endian
The LSB of the data is
placed at the byte with
the lowest address.
Memory Operations
R3 [R1] + [R2]
This type of notation is called RTN (Register Transfer
Notation) Processor
R1 =10
R2 = 20
R3 = 30
Data Transfer
Contents of location are denoted by placing square
brackets around the name of the location
R1 [LOC]
Processor Memory Memory
R1 =10 address location
LOC 10
Data Transfer
Operands
Source 1, Source 2 are source operands
Destination are called destination operands
Basic Instruction Types
Example C= A+B
Add the value of variable A and B and store in C
During compilation three variables A,B,C are
assigned to distinct locations in memory
Action Memory Memory location
address
C [A]+[B] A 10
B 20
C 30
Basic Instruction Types
Three address instruction format
Add A, B ,C
Operation Operand
Operation Operand
Add A
Basic Instruction Types
One address instruction format
Add A
◻ Add the content of memory location to the content of Accumulator
and store the result in accumulator
Memory Memory
Processor address location
Acc= 20 A 10
20+10 = 30
Basic Instruction Types
One address instruction format
Operation Operand
Add A Load A
Store A
Load A - copies the contents of memory location
A into accumulator
Add A Load A
Store A
Store A - copies the contents of accumulator into
memory location A
Move R1 , R2 R1 =10
R2 =10
Basic Instruction Types
Move A , R1
Load A , R1
Processor Memory Memory
Both are same R1 =10
address location
A 10
Basic Instruction Types
Move LOC , R1
Move R1, A
Store R1, A
Processor Memory Memory
Both are same R1 =10
address location
A 10
Basic Instruction Types
Zero address instruction format
It is also possible to use instruction in which
locations of all the operands are defined implicitly.
Such instruction are found in machines that stores
operands in a structure called pushdown stack
Example: Evaluate (A+B) * (C+D)
MUL R1, R2 ; R2 ← R1 * R2 B 20
C 2
MOV R2, X ; M[X] ← R2
D 3
X 150
Unit -1
Add #100, R2
Addressing modes
Immediate mode
Store considers the immediate value 100H as address as
it does not have # sign in front of it.
The Store instruction stores the content of R2 at memory
location 100H.
Store R2,100H
Addressing modes
Example : A= B+6
Move B , R1
Processor
Add #6 , R1 R1 =5 + 6 =11
Memory Memory
address location
Move R1, A A 11
B 5
Addressing modes
Addressing modes to Indirection and Pointers
4. Indirect mode
Addressing modes
Indirect mode
A processor register is used to hold the address of a
memory location where the operand is placed.
In higher-level language, it is referred to as pointers.
The indirect mode is denoted by placing the register
inside the parenthesis.
Here the effective address is the content of memory
location present in the register.
EA=(R)
Addressing modes
Example to execute Add instruction Sum =5+3;
Add (R1) , R0
Processor Memory Memory location
R1 = B address
Add (R1), R0
R0 = 3 + 5
B 5
Addressing modes
Example to execute Add instruction Sum =5+3;
Add (A) , R0
Processor Memory Memory location
address
Add (A), R0
R0 = 3 + 5 A B
B 5
Addressing modes
Adding a list of numbers . Indirect addressing can be
used used to access successive number in the list.
Addressing modes
Addressing modes to deal with lists and array
5. Index mode
6. Base with Index mode
7. Base with Index and Offset mode
Addressing modes
Index mode
◻ The effective address of the operand is generated by adding
a constant value to the contents of a register
◻ Register General purpose registers (Index register)
◻ Index mode symbolically as X(Ri)
◻ X denotes constant value contained in instruction, It can be
an explicit number or symbolic name representing a
numerical value
◻ (Ri) denotes name of the register
◻ EA = X + [Ri]
Addressing modes
2 ways of using Index mode –Offset given as constant
Add 20(R1) , R2
EA = X + [Ri]
X defines the Offset(displacement)
Addressing modes
2 ways of using Index mode –Offset is in index register
Add 1000(R1) , R2
EA = X + [Ri]
X corresponds to memory
location
Addressing modes
Base with Index Mode
we know that Index mode EA = X + [Ri]
• Sometimes second register can be used to contain
the offset X, we can write index mode as (Ri ,Rj)
o Effective address is the sum of the contents of
register Ri and Rj.
• EA = [Ri ]+ [Rj ]
Addressing modes
Base with Index and offset Mode
we know that Index mode EA = X + [Ri]
o Sometimes index mode uses two registers plus a
constant , we can write index mode as X(Ri ,Rj)
o Effective address is the sum of the contents of
register Ri , Rj and a constant.
o We can write the Index mode as X(Ri ,Rj.)
o EA = X + [Ri ]+ [Rj ]
Addressing modes
Addressing modes use PC instead of General purpose
register
8. Relative mode
Addressing modes
Relative mode
The effective address is determined by the index
mode using the PC in place of general purpose register
Ri
Common use to specify target address in Branch
instructions.
Addressing modes
Example of Relative mode
Branch>0 LOOP
Addressing modes
Addressing modes for accessing data items in
successive locations in memory
9. Autoincrement mode
10. Autodecrement mode
Addressing modes
Autoincrement mode
The EA of the operand is the contents of register
specified in instruction.
After accessing the operand, the contents of a
register are automatically incremented to point to
the next item in a list.
Written as (Ri)+
MOVE R0, (R2)+
Addressing modes
Autoincrement mode
Addressing modes
Example MOVE R0, (R2)+
Processor Memory address Memory location
R0 = 5
R2 = LOC(1000) LOC(1000) 5
LOC1(1001)
LOC1(1001)
Addressing modes
Autodecrement mode
The contents of a register are automatically
decremented and are then used as EA of operand
Written as -(Ri)
Addressing modes
Autodecrement mode
Addressing modes
Example MOVE -(R0), R1
Processor Memory address Memory location
R0 = LOC(1001) LOC(1000) 35
LOC(1000) LOC1(1001)
R1 = 35
Generic addressing modes
Byte addressable memory 32-bits
Each number occupies4 byte
Order of matrix n in location NUM
R0-used for summing the results and storing result
R1-to hold order of the matrix
R2,R3,R4-index registers for two source array and destination array
Assembly Language
Types of Instructions
Data Transfer Instructions
Name Mnemonic
Data value is not
Load LD modified
Store ST
Move MOV
Exchange XCH
Input IN
Output OUT
Push PUSH
Pop POP
Data Transfer Instructions
Mode Assembly Register Transfer
Direct address LD ADR AC ← M[ADR]
Indirect address LD @ADR AC ← M[M[ADR]]
Relative address LD $ADR AC ← M[PC+ADR]
Immediate operand LD #NBR AC ← NBR
Index addressing LD ADR(X) AC ← M[ADR+XR]
Register LD R1 AC ← R1
Register indirect LD (R1) AC ← M[R1]
Autoincrement LD (R1)+ AC ← M[R1], R1 ← R1+1
Program-Controlled I/O Example