Module 2
Module 2
• The operation code(op-code) part of the instruction contains three bits and
the meaning of remaining 13 bits depends upon the op-code encountered.
Computer Instruction Set
Instruction Cycle
• The program is executed in the computer by going thru a
cycle for each instruction.
MDR
PC
Instruction
Address
decoder and
lines
MAR control logic
Memory
bus
MDR
Data
lines IR
Y
Constant 4 R0
Select MUX
Add
A B
ALU Sub R( n - 1)
control ALU
lines
Carry -in
XOR TEMP
Instruction
Figure 7.1. Single-bus organization of the datapath inside a processor.
Add (R3), R1
Micro-Operation
• Computer system micro-operations are of four types:
– Arithmetic micro-operations
– Logic micro-operations
– Shift micro-operations
Arithmetic Micro-operations
Logical Micro-operations
Shift Micro-operations
➢R shl R Shift-left register R
LOGICAL SHIFT
• In a logical shift the serial input to the shift
is a 0.
0
CIRCULAR SHIFT
• In a circular shift the serial input is the bit
that is shifted out of the other end of the
register.
0
CF
CF
ARITHMETIC SHIFT
• An left arithmetic shift operation must be
checked for the overflow
sign
0
bit
Before the shift, if the leftmost two bits differ, the shift will
result in an overflow
APPLICATIONS OF LOGIC
• LogicMICROOPERATIONS
micro-operations can be used to
manipulate individual bits or a portions of a
word in a register.
SELECTIVE SET
• In a selective set operation, the bit
pattern in B is used to set certain bits in
A.
1100 A
1010 B (A A + B)
OR Operation
1110 A
Logic Microoperations
SELECTIVE COMPLEMENT
• In a selective complement operation, the
bit pattern in B is used to complement
certain bits in A.
1100 A
1010 B (A A B)
XOR Operation
0110 A
Logic Microoperations
SELECTIVE CLEAR
• In a selective clear operation, the bit
pattern in B is used to clear certain bits
in A.
1100 A
1010 B (A A B’)
0100 A
Logic Microoperations
MASK OPERATION
• The mask operation is similar to selective-
clear operation except that the bits of A are
cleared only where there are corresponding
0’s in B.
1100 A
1010 B (A A B)
AND Operation
1000 A
Logic Microoperations
INSERT OPERATION
• An insert operation inserts a new value into
a group of bits. This is done by first
masking the bits and then ORing them with
the required value.
Ri
Riout
Y in
Constant 4
Select MUX
A B
ALU
Z in
Z out
Figure 7.2. Input and output gating for the registers in Figure 7.1.
• The input and output gates for register Ri
are controlled by signals is Rin and Riout .
• If Rin is set to1 - data available on common
bus are loaded into Ri.
• If Riout is set to1 - the contents of register
are placed on the bus.
• Riout is set to 0 – the bus can be used for
transferring data from other registers .
Data transfer between two
registers:
Transfer the contents of R1 to R4.
1. Enable output of register R1 by setting
R1out=1. This places the contents of R1
on the processor bus.
2. Enable input of register R4 by setting
R4in=1. This loads the data from the
processor bus into register R4.
Performing an Arithmetic or
Logic Operation
• The ALU is a combinational circuit that has no
internal storage.
• ALU gets the two operands from MUX and bus.
The result is temporarily stored in register Z.
• What is the sequence of operations to add the
contents of register R1 to those of R2 and store the
result in R3?
1. R1out, Yin
2. R2out, Select Y, Add, Zin
3. Zout, R3in
Fetching a Word from Memory
Memory -bus Internal processor
data lines MDRoutE MDRout bus
MDR
PC
Instruction
Address
decoder and
lines
MAR control logic
Memory
bus
MDR
Data
lines IR
Y
Constant 4 R0
Select MUX
Add
A B
ALU Sub R( n - 1)
control ALU
lines
Carry -in
XOR TEMP
Instruction
Figure 7.1. Single-bus organization of the datapath inside a processor.
Add (R3), R1
Question
• Write the control sequence to execute
•
Solution 2
• PC out, MAR in, Read, Select4, Add , Zin
• Zout, PCin, Yin, WMFC
• MDRout, IR in,
• IRNUM out, MAR in, Read
• R1out, Yin, WMFC
• MDRout, Select Y, Add, Zin
• Zout, R1in, End
Solution 3
• PC out, MAR in, Read, Select4, Add , Zin
• Zout, PCin, Yin, WMFC
• MDRout, IR in
• IRNUM out, MAR in, Read
• WMFC
• MDRout, MAR in, Read
• R1out, Yin, WMFC
• MDRout , SelectY, Add, Zin
• Zout, R1in, End
Execution of Branch Instructions
• A branch instruction replaces the contents
of PC with the branch target address,
which is usually obtained by adding an
offset X given in the branch instruction.
• The offset X is usually the difference
between the branch target address and
the address immediately following the
branch instruction.
• UnConditional branch
Execution of Branch Instructions
Step Action
Cache
CPU
memory
Memory Organization
– Multiprogramming
• enable the CPU to process a number of
independent program concurrently
– Memory Management System :
• supervise the flow of information between auxiliary
memory and mainRegister
memory
Cache
Main Memory
Magnetic Disk
Magnetic Tape
Memory Hierarchy is to obtain the highest possible access speed while minimizing
the total cost of the memory system
Random
– RAM Chips Access Memory (RAM)
– Static RAM
• Consists of Flip-flops to store binary information.
• Static RAM is easier to use and having short Read/Write cycles
• Used mostly in Cache memory.
– Dynamic RAM
▪ Stores binary information in the form of electric charge stored inside the
capacitor.
▪ The capacitors are provided by MOS transistors.
▪ Refreshing circuit is required to refresh the memory.
• Dynamic RAM offers reduced power consumption and large storage
capacity.
• It is used to construct main memory.
Three State Buffer
Normal input A Output Y=A if C=1
High-impedence if C=0
Control input C
Select S1 0
S0 1
2×4 A0
Decoder 2
Enable E
3
B0
C0
MAIN MEMORY
RAM and ROM Chips
Typical RAM chip
Decoder
3 2 1 0
CS1
CS2
Data
RD 128 x 8
RAM 1
WR
AD7
CS1
CS2
Data
RD 128 x 8
RAM 2
WR
AD7
CS1
CS2
Data
RD 128 x8
RAM 3
WR
AD7
CS1
CS2
RD 128 x 8 Data
RAM 4
WR
AD7
CS1
CS2
Data
1- 7 512 x 8
8
9 } AD9 ROM
Numerical Problems
Q1. a) How many 128x8 RAM chips are needed to provide a memory capacity of 2048
bytes.
b) How any lines of the address bus must be used to access 2048 bytes of memory. How
many of these lines will be common to all chips.
c) How many lines must be decoded for chip select? Specify the size of decoders.
Q2. Extend the memory system of Fig.1 to 4096 bytes of RAM and 4096 bytes of RAM.
List the memory-address map and indicate what size decoders are needed.
Q3. A computer employs RAM chips of 256x8 and ROM chips of 1024x8. The computer
system needs 2K bytes of RAM, 4K bytes of ROM, and four interface units each with four
registers. A memory-mapped I/O configuration used. The two highest-order bits of the
address bus are assigned 00 for RAM, 01 for ROM, and 10 for interface registers.
– Hit Ratio
• the ratio of the number of hits divided by the total CPU references (hits +
misses) to memory
– hit : the CPU finds the word in the cache
– miss : the word is not found in cache (CPU must read main memory)
– A computer with cache access time of 100ns, a main memory access time of
1000 ns, a hit ratio of 0.9 is having average access time of 200ns.
Types of Mapping of Cache
Memory
– Mapping
• The transformation of data from main memory to cache memory
– 1) Associative mapping
– 2) Direct mapping
– 3) Set-associative mapping
– Associative Mapping:
main memory : 32 K x 12 bit word (15 bit address lines)
cache memory : 512 x 12 bit word
– CPU sends a 15-bit address to cache
» Hit : CPU accepts the 12-bit data from cache
» Miss : CPU reads the data from main memory (then data
is written to cache)
Associative Mapping
Main memory
CPU
32K×12 Cache memory
512×12
Argument register
Address Data
0 1 0 0 0 3 4 5 0
0 2 7 7 7 6 7 1 0
2 2 3 4 5 1 2 3 4
Direct mapping :
Direct Mapping
n bit memory address
Tag field (n - k) : Index field (k)
2k words cache memory + 2n words main memory
Tag = 6 bit (15 - 9), Index = 9 bit
6 bits 9 bits
Tag Index
00 000 000
512×12
32K×12
Cache memory
Octal
Hex Main memory address
Address = 9 bits
Address
Data = 12 bits
1FF
Address = 15 bits
3F 1FF Data = 12 bits
Direct Mapping Direct mapping cache with block size of
Memory Index 8 words :
address Memory data address Tag Data
000000 1220 000 00 1220 » 64 block x 8 word = 512
cache words size
Index Tag Data 6 6 3
02777 6710
770 02
Block 63
777 02 6710
(a) Main memory
Set-Associative Mapping
Set-associative mapping : (two-way)
• The access time of a cache memory is 100ns and that of main memory is
1000ns. It is estimated that 80 percent of the memory requests are for read
and the remaining 20 percent for write. The hit ratio for read access only is
0.9. A write-through procedure is used. What is the average access time of
the system considering only memory read cycles. What is the average
access time of the system for both read and write requests. What is the hit
Answer
Answer
– Replacement Algorithm : cache miss or full
• 1) LRU (Least Recently Used):
• 2) Random Replacement:
• 3) FIFO (First-In First-Out) :
– Writing to Cache :
– 1) Write-through :
– 2) Write-back :
– Cache Initialization
• Cache is initialized :
– 1) When power is applied to the computer
– 2) When main memory is loaded with a complete set of
programs from auxiliary memory
– 3) Cache is initialized by clearing all the valid bits to 0.
Virtual Memory
VIRTUAL MEMORY
Give the programmer the illusion that the system has a very large memory,
even though the computer actually has a relatively small main memory
FIFO algorithm selects the page that has been in memory the longest time
Page frames
Virtual Memory
Reference string
7 0 1 2 0 3 0 4 2 3 0 3 2 1 2 0 1 7 0 1
7 7 7 2 2 4 4 4 0 1 1 1
0 0 0 0 0 0 3 3 3 0 0
1 1 3 3 2 2 2 2 2 7
Page frames
Question
The page request are in following order. If
there are three memory frames, show the
execution of the following pages using
a. FIFO b. Optimal c. LRU
6 0 1 3 2 5 0 4 7 1 3 2 6 0 4
Input-Output Organization
❖ Use one common bus for both memory and I/O but have
separate control lines for each. (Isolated I/O)
❖ Use one common bus for memory and I/O with common control
lines. (Memory Mapped I/O)
Input-Output Transfer (IOP)
❑An IOP takes care of input and output tasks.
❑The CPU is assigned the task of initiating all
operations, but I/O instructions are executed
in IOP.
❑When an I/O operation is required, the CPU
informs the IOP where to find the I/O
program and then leaves the transfer details
to the IOP.
Input-Output Transfer (IOP)
Isolated I/O
❑The distinction between memory and I/O
transfer is made through separate read and
control lines.
– Cycle stealing: Allows the DMA controller to transfer one data word
at a time after it must return the control of buses to CPU.
DMA Controller
Initialization of DMA