CHAPTER 12 - Memory Organization PDF
CHAPTER 12 - Memory Organization PDF
S.KHABET
CHAPTER 12:
Memory Organization
Outline
• Memory organization
• Memory hierarchy
• Main Memory
•Memory address map
• Cache Memory
• Associative mapping
• Direct mapping
• Direct Mapped Cache Example
1
Memory Organization (1/6)
Recall:
Information is stored in the memory as a collection of bits.
Collection of bits are stored or retrieved simultaneously is
called a word.
Number of bits in a word is called word length.
Word length can be 16 to 64 bits.
Another collection which is more basic than a word:
Collection of 8 bits known as a “byte”
Bytes are grouped into words, word length can also be
expressed as a number of bytes instead of the number of bits:
Word length of 16 bits, is equivalent to word length of 2
bytes.
Words may be 2 bytes (older architectures), 4 bytes (current
architectures), or 8+ bytes (modern architectures).
2
Memory Organization (2/6)
Accessing the memory to obtain information requires specifying
the “address” of the memory location.
Recall that a memory has a sequence of bits:
Assigning addresses to each bit is impractical and
unnecessary.
Typically, addresses are assigned to a single byte.
“Byte addressable memory”
Suppose k bits are used to hold the address of a memory
location:
Size of the memory in bytes is given by: 2^k
where k is the number of bits used to hold a memory address.
E.g., for a 16-bit address, size of the memory is 2^16= 65536 bytes
3
Memory Organization (3/6)
Byte 0
Memory is viewed as a sequence of
bytes.
Address of the first byte is 0
k
Address of the last byte is 2 – 1.
Where k is the number of bits used to
hold memory address.
4
Memory Organization (4/6)
Consider a memory organization:
16-bit memory addresses
Word #0 Byte 0
Size of the memory is = 2^16 =65536 B
Byte 1
Byte 2 [Byte 0..Byte 65535]
Byte 3 Word length is 4 bytes
Word #1 Byte 4
Number of words = Memory size(bytes) = ?
Word length(bytes)
=16384 words
Word #0 starts at Byte #0.
Word #? Byte 65532 Word #1 starts at Byte #4.
Byte 65533
Byte 65534
Byte 65535 Last word (Word #?) starts at Byte#?
5
Memory Organization (5/6)
Byte 0 Word #0
Byte 1
Byte 2
MAR Byte 3
Byte 4 Word #1 MDR
MAR register
contains the
address of the
memory location
addressed
Addr 65532 Byte 65532 Word #16383
Byte 65533 MDR contains either the
Byte 65534 data to be written to that
Byte 65535
address or read from that
address.
6
Memory Organization (6/6)
Memory read or load:
Place address of the memory location to be read from, into
MAR.
Issue a Memory_read command to the memory.
Data read from the memory is placed into MDR
automatically (by control logic).
8
Memory Hierarchy (2/3)
Cache memory is sometimes used to increase the speed of
processing by making current programs and data available to
the CPU at a rapid rate (extremely fast), Whose access time is
close to processor logic clock cycle time.
9
Memory Hierarchy (3/3)
Memory hierarchy in a computer system
Auxiliary memory
(Secondary)
Magnetic
tapes Main
I/O
Processor memory
Magnetic
disks
CPU Cache
memory
10
Main Memory (1/4)
The main 2 types of main memory are:
RAM which is to used to refer to a read/write random-access
memory
ROM which is to used to refer to a read only random-access
memory.
11
Main Memory (2/4)
The stored charge on the capacitors tend to discharge with time
and the capacitors must be periodically recharged by refreshing
the dynamic memory.
The dynamic RAM offers reduced power consumption and
larger storage capacity in single memory chip.
But the static RAM is easier to use and has shorter read and
write cycles.
ROM is used for storing programs that are permanently
resident in the computer.
The ROM portion of main memory is needed for storing an
initial program called a bootstrap loader.
The bootstrap loader is a program whose function is the start
the computer software operating when power is turned on.
12
Main Memory (3/4)
RAM and ROM chips are available in a variety of sizes.
For example of a 1024 x 8 memory can be constructed with
128 x 8 RAM chips and 512 x 8 ROM chips.
15
Main Memory: Memory address map (2/4)
Memory Address Map for Microprocomputer
Address bus
Component Hexadecimal address 10 9 8 7 6 5 4 3 2 1
RAM 1 0000-007F 0 0 0 X X X X X X X
RAM 2 0080-00FF 0 0 1 X X X X X X X
RAM 3 0100-017F 0 1 0 X X X X X X X
RAM 4 0180-01FF 0 1 1 X X X X X X X
ROM 0200-03FF 1 X X X X X X X X X
16
Main Memory: Memory address map (3/4)
Although there are 16 lines in the address bus, the table shows
only 10 lines because the other 6 are not used in this example
and are assumed to be zero.
The small x's under the address bus lines designate those lines
that must be connected to the address inputs in each chip.
The RAM chips have 128 bytes and need 7 address lines.
The ROM chip has 512 bytes and needs 9 address lines.
The x's are always assigned to the low – order bus lines:
lines 1 through 7 for the RAM
and lines 1 through 9 for the ROM.
The distinction between a RAM and ROM address is done
with another bus line. This can be done by choosing line 10 for
this purpose. 17
Main Memory : Memory address map (4/4)
Memory address map & Connection to CPU
CPU
16 – 11 10 9 8 7 -1 RD WR Data bus CS1
CS2
RD 128X8
WR AM 1
Decoder AD7
3210 CS1
CS2
RD 128X8
WR RAM 2
Data
CS1 AD7
CS2
RD 128X8
WR RAM 3
CS1
CS2 AD7
RD 128X8
WR RAM 4
AD7
CS1
CS2
512X8
ROM
AD9
18
Cache Memory (1/5)
Analysis of a large number of typical programs has shown that
the references to memory at any given interval of time tent to be
confined within a few localized areas in memory.
If the active portions of the program and data are placed in a fast
small memory, the average memory access time can be reduced,
thus reducing the total execution time of the program.
19
Cache Memory (2/5)
When the CPU refers to memory and finds the word in cache, it is
said to produce a hit.
20
Cache Memory (3/5)
The ratio of the number of hits divided by the total CPU
references to memory (hits plus misses) is the hit ratio,
[Hit ratio = hits/ (hits + misses)]
Average access time for a memory with a single-level cache
formula. A = C + (1-H)M
A is the average access time of the system
M is the access time of the main memory
C is the access time of the cache
H is the percent of accesses that are satisfied from the
cache.
Example, a computer with cache access time of 100 ns, a main
memory access time of 1000 ns , and a hit ratio of 0.9,
produces an average access time of 200 ns.
21
Cache Memory (4/5)
The transformation of data from main memory to
cache memory is referred to as a mapping process.
Three types of mapping procedures are of practical
interest when considering the organization of cache
memory.
Direct mapping.
Associative mapping.
Set-associative mapping.
22
Cache Memory (5/5)
Small amount of fast memory
Sits between normal main memory and CPU
May be located on CPU chip or module
For every word stored in cache, there is a duplicate copy in main
memory.
To illustrate these 3 mapping procedures, a specific example of a
memory organization will be used as shown.
Argument register
15-bit Address 12-bit Data
01000 3450
02777 6710
22345 1234
24
Cache Memory: Associative Mapping (2/2)
The associative memory stores both the address and content
(data) of the memory word.
This permits any location in cache to store any word from
main memory.
A CPU address of 15 bits is placed in the argument register
and the associative memory is searched for a matching
address.
If the address is found , the corresponding 12- bit data is read
and sent to the CU.
If no match occurs, the main memory is accessed for the
word.
The address-data pair is then transferred to the associative
cache memory based on a replacement algorithm.
25
Cache Memory: Direct mapping (1/5)
Associative memories are expensive compared to random access
memories, which can be used for the cache, because of the added
logic associated with each cell.
This organization is shown in the following diagram:
6 bits 9 bits
Tag Index
00 000 000
Octal 512 X12
Octal 32 k X12
Address Cache memory
Address Main memory
Address= 9 bits
Address= 15 bits
Data= 12 bits
Data= 12 bits 777
77 777 26
Cache Memory: Direct mapping (2/5)
1. Direct mapping cache Organization:
Block size of one word (simplest cache)
Memory
address Memory data Index
00000 1220 address Tag data
000 00 1220
00777 2340
01000 3450
01777 4560
02000 5670
777 02 6710
02777 6710
Cache memory
Main memory 27
Cache Memory: Direct mapping (2/5 bis)
Address Main Memory Cache 4-Block Direct
0000 0 Index Mapped Cache
0001 1
0010 2
00 0
0011 3
01 1
0100 4
10 2
0101 5
11 3
Memory block address
0110 6
0111 7 Tag Index
1000 8
1001 9
1010 10 Index determines block in cache
1011 11 If number of cache blocks is power of
1100 12 2, then cache index is just the lower n
1101 13
bits of memory address
1110 14
1111 15 28
Cache Memory: Direct mapping (3/5)
2. Direct mapping cache Organization:
Block size of eight words
Index Tag Data
000 01 3450
Block 0
01 6578
6 bits 6 bits 3 bits
007
010 Tag Block Word
Block 1
017 Index
770 02 9989
Block 63
02 6710
777 29
Cache Memory: Direct mapping (3/5 bis)
If block size > 1 word, rightmost bits of index are really the
offset of a word (possibly byte number) within the indexed block
30
Cache Memory: Direct mapping (4/5)
The CPU address of 15 bits is divided into two fields.
The 9 least significant bits constitutes the index field and the
remaining 6 bits form the tag field.
The number of bits in the index field = the number of
address bits required to access the cache memory.
In the general case , there are 2^k words in cache memory and
2^n words in main memory . The n-bits memory address is
divided into two fields:
k bits for the index to access the cache,
n-k bits for the tag field.
The direct mapping cache organization uses:
The n-bit address to access the main memory,
And the k-bit index to access the cache.
31
Cache Memory: Direct mapping (5/5)
Each word in cache consists of the data word and its
associated tag.
34