Module4_1
Module4_1
• 2 types
• 1 dimensional
• 2 dimensional
- They exhibit two stable states, which can be used to represent binary 1 and 0.
- They are capable of being written into (at least once) to set the state.
• Least Significant Byte (LSB) is the right-most bit in a string - because it has the least
effect on the value of the binary number.
• Most Significant Byte (MSB) - the left-most byte that carries the greatest numerical
value.
• In Big Endian, the MSB of the data is placed at the byte with the lowest address. (First
byte stored in the memory first)
• In Little Endian, the LSB of the data is placed at the byte with the lowest address. (Last
byte stored in the memory first)
Byte Storage Methods
• In Big Endian, the MSB of the data is placed at the byte with the lowest address. (First
byte stored in the memory first)
• In Little Endian, the LSB of the data is placed at the byte with the lowest address. (Last
byte stored in the memory first)
Byte Storage Methods
• Big Endian - the most common format in data networking (TCP, UPD, IPv4 and IPv6 are using
Big endian order to transmit data)
Memory -
Block Diagram
Design of scalable memory using RAM’s
RAM Chips
Design of scalable memory using RAM’s
• The logic 1 and 0 are normal digital signals.
RAM Chips • High impedance state behaves like an open circuit, which means
that the output does not carry a signal and has no logic
significance.
• The unit is in operation only when CS1 = 1 and CS2 = 0. The bar on
top of the second select variable indicates that this input is enabled
when it is equal to 0.
• If the chip select inputs are not enabled, or if they are enabled but
the read or write inputs are not enabled, the memory is inhibited
(temporarily inaccessible) and its data bus is in a high-impedance
state (the output of a buffer is disconnected from the output bus).
• When CS1 = 1 and CS2 = 0, the memory can be placed in a write or
read mode.
• When the WR input is enabled, the memory stores a byte from the
data bus into a location specified by the address input lines.
• When the RD input is enabled, the content of the selected byte is
placed into the data bus. The RD and WR signals control the
memory operation as well as the bus buffers associated with the
bidirectional data bus .
Read Only Memory (ROM)
ROM Types
Read Only Memory (ROM)
• A ROM chip is organized externally in a similar manner.
ROM Chips However, since a ROM can only read, the data bus can only
be in an output mode
• For the same-size chip, it is possible to have more bits of
ROM than of RAM, because the internal binary cells in ROM
occupy less space than in RAM.
• For this reason, the diagram specifies a 512-byte ROM, while
the RAM has only 128 bytes.
• The nine address lines in the ROM chip specify any one of
the 512 bytes stored in it.
• The two chip select inputs must be CS1 = 1 and CS2 = 0 for
the unit to operate. Otherwise, the data bus is in a high-
• No R/W signal – Default Read only. impedance state.
• Data Bus - unidirectional • There is no need for a read or write control because the unit
can only read. Thus when the chip is enabled by the two
select inputs, the byte selected by the address lines appears
on the data bus.
Construction of Larger Size memory
• Mix of RAM and ROM
• Decoder Circuit
• Address Lines
• Data Lines
• SELECT signal
Memory Connection to CPU
Address Calculation
(From – To)
-calculated from 16 bit address Bus line 10 select RAM or ROM
- Hexadecimal format Bus lines 8 and 9 are used to
No. of Address line bits (x) is given by N=2x select one RAM out of 4 RAMs
No. of data bus = No. of columns (Word size)
Assumptions
RAM size: 128 * 8 ----- 7 bit address bits needed, No. of Data Lines --- 8
ROM size: 512 * 8 ------ 9 bit address bits required, No. of Data Lines --- 8
Memory Design - Memory Interface
Address Map
Address Calculation
(From Address) v v v v
-calculated from 16 bit address
- Hexadecimal formatSubstitute x=0 to get ‘From’ address X=0
Address Calculation
(To Address) v v v v
-calculated from 16 bit address
- Hexadecimal formatSubstitute x=1 to get ‘To’ address X=1
How many 1024x 8 RAM chips are needed to provide a memory capacity of 2048 x 8?
How many 1024x 4 RAM chips are needed to provide a memory capacity of 2048 x 8?
4 4 4 4
Data (0-3) Data (0-3) Data (0-3) Data (0-3)
Read/write Control
4 4 4 4
1
Memory Design - Memory Interface Address Map
Problem – 2 (CASE 1) – Increasing the number of words (Rows)
Design 1024 × 8 - bit RAM using 256 × 8 - bit RAM
Y=2 address lines 8 and 9 will select one RAM among 4 RAM
v v v v
v v v v
Data
Address Bus 256 × 8 Bus
0 8 RAM 8
1
A8 CS R/W
2×4 2
A9 decoder
Data
3 Address Bus 256 × 8 Bus
8 RAM 8
CS R/W
Data
Address Bus 256 × 8 Bus
8 RAM 8
CS R/W
8 R/W
Data
Bus
Memory Design - Memory Interface Address Map
Data
8 Address Bus 256 × 8 Bus
Address Bus 8 RAM 8
A9 A8 A0 – A7 R/W
CS
Data
Address Bus 256 × 8 Bus
8 RAM 8
CS R/W
Data
Address Bus 256 × 8 Bus
8 RAM 8
CS R/W
Data
Address Bus 256 × 8 Bus
8 RAM 8
CS R/W
8 R/W
Data
Bus
256 × 8
Data
987-0 RAM 1 r/w
8
8
256 × 8
RAM 2
8
2×4
Decoder
256 × 8
3 2 1 0 RAM 3
256 × 8
RAM 4
8
Memory Design - Memory Interface Address Map
Problem – 3 (CASE 3) – Increasing the Words & Word size (Rows & Columns)
Design 256 × 16 – bit RAM using 128 × 8 – bit RAM chips
4
Memory Design - Memory Interface Address Map
v v v v
v v v v
Address Bus
128 × 8 128 × 8
RAM 1.1 RAM 1.2
1×2
Decoder
1 0
16
8
8
128 × 8 128 × 8
RAM 2.1 RAM 2.2
16
8
8
Memory Design - Memory Interface Address Map
Problem – 4: Design 256 × 16 – bit RAM using 256 × 8 – bit RAM chips and 256 × 8 – bit ROM
using 128 × 8 – bit ROM chips.
RAM Chip calculation
Solution: p = 256 / 256 = 1; q = 16 / 8 = 2
p×q=1× 2=2 RAM2 chips are required 1 row 2 chips (cols)
4
Memory Design - Memory Interface Address Map
Problem – 4: Design 256 × 16 – bit RAM using 256 × 8 – bit RAM chips and 256 × 8 – bit ROM
using 128 × 8 – bit ROM chips.
ROM Chip calculation
Solution: p = 256 / 128 = 2; q=8/8=1
p×q=2× 1=2 ROM2 chips are required 2 chips(rows) , 1 column
4
Memory Design - Memory Interface Address Map
v v v v
v v v v
1×2 1×2 8
Decoder Decoder
1 0 1 0
128 × 8
ROM 2
●
256 × 8 256 × 8
RAM 1.1 RAM 1.2
16
8
8
Memory Design - Memory Interface Address Map
Problem – 5
• A computer employs RAM chips of 128 x 8 and ROM chips of 512 x 8. The computer system needs
256 x 8 of RAM, 1024 x 16 of ROM, and two interface units with 256 registers each. A memory
mapped I/O configuration is used. The two higher -order bits of the address bus are assigned 00 for
RAM, 01 for ROM, and 10 for interface registers.
• a. Compute total number of decoders are needed for the above system?
3 Interface 256 2 1 2 8 1 2 11
4
Memory Design - Memory Interface Address Map
Solution: p = 1024 / 512 = 2; q = 16 / 8 = 2
2.ROM p×q=2× 2=4 RAM4chips are required 2chips(rows), 2chips(cols)
3 Interface 256 2 1 2 8 1 2 11
4
Memory Design - Memory Interface Address Map
3.Interface p = number of interfaces=2(input is given)
q is 1 always for interfaces. p*q= 2 * 1 = 2
Z – Number of 2 (select
2x = 256 (Number of registers) 2y = p=2
the RAM or ROM or
X= 8 y= 1
interface)
2 interfaces are required 2 interfaces(rows), 1 column
S.NO Memory NxW N1 x W1 P q p*q x y z Total
3 Interface 256 2 1 2 8 1 2 11
4
Memory Design - Memory Interface Address Map
Component Hexadecimal Address Address Bus
From To 15 - 12 11 10 9 8 7 6 5 4 3 2 1 0
X=address lines(RAM7,ROM9,interface8
Y=1 Z=2
Address Bus
11 10 128 × 8 Data r/w
9876-0 RAM 1
128 × 8
RAM 2
0
1
512 × 8 512 × 8
ROM 1.1 ROM 1.2
3×8 2
Decoder
3
4 512 × 8 512 × 8
ROM 2.1 ROM 2.2
5
Select Interface 1
Ch. Address r/w Data
Select Interface 2
Ch. Address r/w Data
Memory Design - Memory Interface Address Map
Problem – 6
• Suppose that a 2M × 16 RAM memory is built using 256K × 8 RAM chips and 1K x 8 ROM
memory is build using 256 x 8 ROM chips with the word addressable memory, find the
following:
• a) How many RAM chips and ROM chips are necessary?
• b) If we were accessing one full word in RAM, how many chips would be involved?
• c) How many address bits are needed for each RAM chip?
• d) How many memory banks are required? Hint: number of banks are addressable units in
main memory and RAM chips
• e) If high-order interleaving is used, where would address (1B)16 be located? Also, for a
low-order interleaving?
Memory Design - Memory Interface Address Map
Problem – 6 - Solution
• a) 16 RAMS , 4 ROMS
• b) Each RAM chip is 256K × 8, so to access one full word (2 bytes), 2 RAM chips would be
involved.
• c) The 256K × 8 RAM chip has 18 address bits (2^18 = 256K), so each RAM chip would
need 18 address bits.
• d) 8
• e) module 0 – word 27
module 3 - word 3
Cache Memory
Yes
Direct Mapping
Fully Associative
Management
Techniques Block Identification
Tag
Index
Offset
Cache Memory Management
Techniques
FCFS
Optimal
Write Through
Write back
Update Policies
Write around
Write allocate
Direct Mapping
Fully Associative
Management
Techniques Block Identification
Tag
Index
Offset
Cache Memory Management
Techniques
FCFS
Write allocate
Mapping - Basics
In SM to MM – The
terms Pages and
Frames are used.
In MM to CM – The
terms Blocks and
Lines are used.
Blocks – MM Blocks
Cache Lines - Cache Blocks
Mapping - Basics 4 words per Block
16 Blocks
Mapping - Basics 4 words per Block
In Main memory,
MM Size – 16 blocks
Cache Size – 4 blocks(Lines)
• Associative Mapping
• Many to Many Mapping
• Map to any Cache Line
How a block is
identified in 2 bits identifies a word in a Block
cache with Cache
MM Address Blocks/Lines Many–to–One
bits? Relationship
Main Memory
Block is identified by Cache
first 4 bits of PA Memory
Mapping Techniques - Direct Mapping
Mapping 64 words of Main memory on to 16 words of Cache
Mapping – Direct Mapping
MM Blocks
How a block is
identified in 2 bits identifies a word in a Block
cache with Cache Blocks/
Lines
MM Address
bits?
Main Memory
Block is identified by Cache
first 4 bits of PA Memory
Mapping Techniques - Direct Mapping
Mapping 64 words of Main memory on to 16 words of Cache
Tag bits MM Blocks Line Number/Index
How a Word in
a block is TAG BITS LINE 2 bits
identified in Cache Blocks/ NUMBER identifies a
cache with Lines word in
MM Address both
MM/CM
bits? Block
Main Memory
Word is identified by Cache
last 2 bits of PA Memory
Mapping Techniques - Direct Mapping
Mapping 64 words of Main memory on to 16 words of Cache
Tag bits MM Blocks Line Number(Index)
Cache Blocks/
Lines
=MM Size/ Cache Size =Cache Size/ Line Size=Line Size in powers of 2
in powers of 2 in powers of 2
PA Bits Calculation:
MM Words = 4096*16 words = 65536 words, So, No. of PA bits => 216 => 16 bits
BLOCK / LINE bits:
No. of MM blocks : 4096, So, No. of bits to represent a block =>212 => 12 bits (Block bits + Tag Bits)
LINE OFFSET (WORD) Bits:
Each Block – 16 words => No. of bits for 16 words = 24 => 4 bits
TAG Bits & Block Bits:
No. of Lines in cache (128 blocks) = CACHE size/Block Size = 2048 / 16 = 128.
Block bits (128 lines/blocks) => 27 => 7 bits.
Tag Bits => Total Block bits – Block bits = 12-7 = 5 bits
Mapping Techniques - Direct Mapping
In direct mapping,
⚫ Cache Miss
⚫ A referenced item is not present in the cache
⚫ Hit ratio
⚫ Ratio of number of hits to total number of references = > number of hits/(number of hits + number of
Miss)
⚫ Miss penalty
⚫ Additional cycles required to serve the miss
⚫ Time required for the cache miss depends on both the latency and bandwidth
⚫ Latency – time to retrieve the first word of the block
⚫ Bandwidth – time to retrieve the rest of this block
Types of Cache Miss
• Compulsory Miss / Cold Miss
• Conflict Miss/ Collision miss/ Interference miss
• Capacity Miss – Not because of mapping techniques … because of size of cache.
Mapping Techniques - Direct Mapping -
Drawbacks
• Drawback – Conflict Miss
Compulsory
Miss
Conflict Miss
Mapping Techniques – (Fully) Associative
Mapping
• To reduce Conflict Miss ----- Associative Mapping
Many–to–Many
• A block of main memory can map to any Relationship
line of the cache that is freely available
at that moment.
• This makes fully associative mapping
more flexible than direct mapping.
• All the lines of cache are freely
available.
• When all the cache lines are occupied,
then one of the existing blocks will have
to be replaced.
Mapping Techniques – (Fully) Associative
Mapping
• Entire block number bits are used as
TAG bits --- (Fully Associative)
• No need of specifying the block number. Many–to–Many
Relationship
PA Address Calculation - Direct &
Associative
Direct Mapping Associative Mapping
Mapping Techniques – (Fully) Associative
Mapping
Disadvantages: Need of Replacement Algorithm:
• A replacement algorithm is required. • A replacement algorithm is
• During retrieval, all the blocks needs to required.
be checked for the data. • Replacement algorithm suggests the
block to be replaced if all the cache
lines are occupied.
• Thus, replacement algorithm like
FCFS Algorithm, LRU Algorithm etc is
employed.
Associative Mapping – Calculation of PA
Bits needed
PA = MM Size = 2N
N BITS
• Block ‘j’ of main memory can map to set number (j mod 3) only of the cache.
• Within that set, block ‘j’ can map to any cache line that is freely available at
that moment.
• If all the cache lines are occupied, then one of the existing blocks will have
to be replaced.
Mapping Techniques – Set Associative
Mapping
PA Bits Calculation:
MM Words = 4096*16 words = 65536 words, So, No. of PA bits => 216 => 16 bits
BLOCK / LINE bits:
No. of MM blocks : 4096, So, No. of bits to represent a block =>212 => 12 bits (Block bits + Tag Bits)
LINE OFFSET (WORD) Bits:
Each Block – 16 words => No. of bits for 16 words = 24 => 4 bits
TAG Bits & Block Bits:
No. of Lines in cache (128 blocks) = CACHE size/Block Size = 2048 / 16 = 128.
No. of lines = 128 =>(2-way set associative)=> No. sets =128/2 = 64 sets… No. of bits for representing Set = 26 = 6 bits.
Tag Bits => Total Block bits – Block bits = 12-6 = 6 bits
Mapping Techniques – Set Associative
Mapping
• If k = 1, then k-way set associative mapping becomes direct mapping i.e
• If k = Total number of lines in the cache, then k-way set associative mapping
becomes fully associative mapping.
Solution:
Calculation of PA bits:
Solution: Physical Address Split: Tag Bits =K * (MM Size/ Cache Size)
in powers of 2
Cache Memory:
Number of lines and sets
(OR)
Cache size
Mapping Techniques – Set Associative
Mapping - Problems
Example 5
Mapping Techniques – Set Associative
Mapping - Problems
Example 6
Mapping Techniques – Set Associative
Mapping - Problems
Example 7
Mapping Techniques – Set Associative
Mapping - Problems
Example 8
Mapping Techniques – Set Associative
Mapping - Problems
Example 9
• Here, in the question "word" is mentioned and even "Where in the cache is the word from
memory location“ is asked. So, word addressing is in use.
So, offset bits = 2 for 4 words.
• No. of sets=no of lines/p(way)
• No. of lines=cache size /line size
Fully Associative
Management
Techniques Block Identification
Tag
Index
Offset
Cache Memory Management
Techniques
FCFS
Block Optimal
Write around
Write allocate
Cache : Block Replacement Policies
• Cache memory size < main memory size
• Processor fetches data from cache memory to perform execution operation
• So, when required block is not found within cache, then main memory block is transferred
to cache and previously present block is replaced---- Cache replacement policies are
needed….
• Replacement policies – used in
• Set-associative cache
• Fully – Associative/ Associative Cache
• Cache Replacement Policies:
• FIFO
• Optimal Algorithm
• LRU
• MRU
Cache : Block Replacement Policies - FIFO
Cache : Block Replacement Policies - FIFO
Cache : Block Replacement Policies - Optimal
Cache : Block Replacement Policies - Optimal
Cache : Block Replacement Policies - LRU
Cache : Block Replacement Policies - LRU
Cache : Block Replacement Policies - MRU
Most Recently Used
Fully Associative
Management
Techniques Block Identification
Tag
Index
Offset
Cache Memory Management
Techniques
FCFS
Write Through
Write back
Update Policies
Write around
Write allocate
Cache Memory – Update Policies
• Update policy - determines how a cache & Main Memory is updated
after an operation.
• Write through
Used on Write HIT
• Write back
• Write around
Used on Write MISS
• Write Allocate
Update Policy - Write-through
• Correspond to items currently in the cache (i.e. write Hit)
• Systems that write to main memory each time as well as to cache
• It's the easiest policy to implement, but it lowers the cache's
performance.
• It's used when there are no frequent writes to the cache.
TAvg = (h × TC ) + (1-h) × TM