CHAPTER 3, Memories
CHAPTER 3, Memories
MEMORIES
3.1. Introduction
The computer’s memory stores data, instructions required during the processing of data, and output
results. Storage may be required for a limited period, instantly, or, for an extended period. Different
types of memories, each having its own unique features, are available for use in a computer. The
cache memory, registers, and RAM are fast memories and store the data and instructions
temporarily during the processing of data and instructions. The secondary memory like magnetic
disks and optical disks has large storage capacities and store the data and instructions permanently,
but are slow memory devices. The memories are organized in the computer in a manner to achieve
high levels of performance at the minimum cost. In this chapter, we will discuss different types of
memories, their characteristics and their use in the computer.
Computer memory stores different kinds of data like input data, output data, intermediate results,
etc., and the instructions. Binary digit or bit is the basic unit of memory. A bit is a single binary
digit, i.e., 0 or 1. A bit is the smallest unit of representation of data in a computer. However, the
data is handled by the computer as a combination of bits. A group of 8 bits form a byte:
• One byte is the smallest unit of data that is handled by the computer.
• One byte (8 bit) can store 2 8 = 256 different combinations of bits, and thus can be used to
represent 256 different symbols. In a byte, the different combinations of bits fall in the range
00000000 to 11111111. A group of bytes can be further combined to form a word. A word can
be a group of 2, 4 or 8 bytes.
bit = 0 or 1
1|Pa ge
1 Megabyte (MB) = 220 = 1024KB
The memory is characterized based on two key factors: capacity and access time.
• Capacity is the amount of information (in bits) that memory can store.
• Access time is the time interval between the read/ write request and the availability of data.
The lesser the access time, the faster is the speed of memory.
Ideally, we want the memory with fastest speed and largest capacity. However, the cost of fast
memory is very high. The computer uses a hierarchy of memory that is organized in a manner to
enable the fastest speed and largest capacity of memory. The hierarchy of the different memory
types is shown in Figure 3.1.
The Internal Memory and External Memory are the two broad categories of memory used in the
computer. The Internal Memory consists of the CPU registers, cache memory and primary
2|Pa ge
memory. The internal memory is used by the CPU to perform the computing tasks. External
Memory is also called the secondary memory. The secondary memory is used to store the large
amount of data and the software.
2. Temporary storage.
3. Fast access.
4. High cost.
Registers, cache memory, and primary memory constitute internal memory. The primary memory
is further of two kinds: RAM and ROM. Registers are the fastest and the most expensive among
all the memory types. The registers are located inside the CPU and are directly accessible by the
CPU. The speed of registers is between 1-2 ns (nanosecond). The sum of the size of registers is
about 200B. Cache memory is next in the hierarchy and is placed between the CPU and the main
memory. The speed of cache is between 2-10 ns. The cache size varies between 32 KB to 4MB.
Any program or data that has to be executed must be brought into RAM from the secondary
memory. Primary memory is relatively slower than the cache memory. The speed of RAM is
around 60ns. The RAM size varies from 512KB to 64GB.
3|Pa ge
3. Relatively slower access.
4. Stores data and instructions that are not currently being used by CPU but may be required later
for processing.
To get the fastest speed of memory with largest capacity and least cost, the fast memory is located
close to the processor. The secondary memory, which is not as fast, is used to store information
permanently, and is placed farthest from the processor. With respect to CPU, the memory is
organized as follows:
• Registers are placed inside the CPU (small capacity, high cost, very high speed)
• Cache memory is placed next in the hierarchy (inside and outside the CPU)
• Primary memory is placed next in the hierarchy
• Secondary memory is the farthest from CPU (large capacity, low cost, low speed)
The speed of memories is dependent on the kind of technology used for the memory. The registers,
cache memory and primary memory are semiconductor memories. They do not have any moving
parts and are fast memories. The secondary memory is magnetic, or optical memory has moving
parts and has slow speed.
Information has to migrate between the levels of a hierarchy. The higher alevel is in the hierarchy,
the smaller its capacity is: it can accommodate only a small part of the logical address space.
Transfers between levels take place in amounts called blocks. A block may be:
• fixed size
• variable size.
Fixed size blocks are the most common; in this case the size of the memory is a multiple of the
block size. Note that it is not necessary that blocks between different memory levels all have the
same size. It is possible that transfers between level i and i+1 are done with blocks of size bi,
while transfers between level i+1 and i+2 isdone with a different block size bi+1. Generally, the
4|Pa ge
block size is a power of 2 bytes, but there is no rule for this, and, as a matter of fact, deciding the
block size is a difficult problem as we shall discuss soon.
The reason for having a memory hierarchy is that we want a memory that behaves like a very
fast one and is cheap as a slower one. For this to happen, most of the memory access must be
found in the upper level of the hierarchy. In this case we say we have a hit. Otherwise, if the
addresseditem is in a lower level of the hierarchy, we have a miss; it will take longeruntil the
addressed item gets to the CPU.
• The hit time is the time it takes to access an item in the upper level of the memory
hierarchy; this time includes the time spent to determine if there isa hit or a miss. In the
case of a miss there is a miss penalty because the item accessed has to be brought from
the lower level in memory into the higher level, and then the sought item delivered to the
caller (this is usuallythe CPU). The miss penalty includes two times:
• The access time for the first element of a block into the lower levelof the hierarchy;
• The transfer time for the remaining parts of the block; in the caseof a miss a whole block
is replaced with a new one from the lowerlevel.
Registers are very high-speed storage areas located inside the CPU. After CPU gets the data and
instructions from the cache or RAM, the data and instructions are moved to the registers for
processing. Registers are manipulated directly by the control unit of CPU during instruction
execution. That is why registers are often referred to as the CPU’s working memory. Since CPU
uses registers for the processing of data, the number of registers in a CPU and the size of each
register affect the power and speed of a CPU. The more the number of registers (ten to hundreds)
and bigger the size of each register (8 bits to 64 bits), the better it is.
Cache memory is placed in between the CPU and the RAM. Cache memory is a fast memory,
faster than RAM. When the CPU needs an instruction or data during processing, it first looks in
5|Pa ge
the cache. If the information is present in the cache, it is called a cache hit, and the data or
instruction is retrieved from the cache. If the information is not present in cache, then it is called a
cache miss and the information is then retrieved from RAM.
Cache memory improves the speed of the CPU, but it is expensive. Type of Cache Memory is
divided into different levels that are L1, L2, L3:
i. Level 1 (L1) cache or Primary Cache L1 is the primary type cache memory. The Size of
the L1 cache very small comparison to others that is between 2KB to 64KB, it depends on
computer processor. It is an embedded register in the computer microprocessor (CPU). The
Instructions that are required by the CPU that are firstly searched in L1 Cache. Example of
registers are accumulator, address register, Program counter etc.
ii. Level 2 (L2) cache or Secondary Cache L2 is secondary type cache memory. The Size
of the L2 cache is more capacious than L1 that is between 256KB to 512KB. L2 cache is
located on computer microprocessor. After searching the Instructions in L1 Cache, if not
found then it searched into L2 cache by computer microprocessor. The high-speed system
bus interconnecting the cache to the microprocessor.
iii. Level 3 (L3) cache or Main Memory L3 cache is larger in size but also slower in speed
than L1 and L2, its size is between 1MB to 8MB. In Multicore processors, each core may
have separate L1 and L2, but all core share a common L3 cache. L3 cache double speed
than the RAM.
6|Pa ge
The advantages and disadvantages of cache memory are as follows:
➢ Advantages
➢ Disadvantages
Primary memory is the main memory of computer. It is a chip mounted on the motherboard of
computer. Primary memory is categorized into two main types: Random access memory (RAM)
and read only memory (ROM). RAM is used for the temporary storage of input data, output data
and intermediate results. The input data entered into the computer using the input device, is stored
in RAM for processing. After processing, the output data is stored in RAM before being sent to
the output device. Any intermediate results generated during the processing of program are also
stored in RAM. Unlike RAM, the data once stored in ROM either cannot be changed or can only
be changed using some special operations. Therefore, ROM is used to store the data that does not
require a change.
7|Pa ge
➢ Types of Primary Memory
The Word “RAM” stands for “random access memory” or may also refer to shortterm memory.
It’s called “random” because you can read store data randomly at any time and from any physical
location. It is a temporal storage memory. RAM is volatile that only retains all the data as long as
the computer powered. It is the fastest type of memory. RAM stores the currently processed data
from the CPU and sends them to the graphics unit.
• Static RAM (SRAM): Static RAM is the form of RAM and made with flip-flops and used for
primary storage are volatile. It retains data in latch as long as the computer powered. SRAM
is more expensive and consumes more power than DRAM. It used as Cache Memory in a
computer system. As technically, SRAM uses more transistors as compared to DRAM. It is
faster compared to DRAM due to the latching arrangement, and they use 6 transistors per data
bit as compared to DRAM, which uses one transistor per bit.
• Dynamic Random Access Memory (DRAM): It is another form of RAM used as Main
Memory, its retains information in Capacitors for a short period (a few milliseconds) even
though the computer powered. The Data is Refreshed Periodically to maintain in it. The DRAM
is cheaper, but it can store much more information. Moreover, it is also slower and consumes
less power than SRAM.
ROM is the long-term internal memory. ROM is “Non-Volatile Memory” that retains data without
the flow of electricity. ROM is an essential chip with permanently written data or programs. It is
similar to the RAM that is accessed by the CPU. ROM comes with pre-written by the computer
manufacturer to hold the instructions for booting-up the computer.
8|Pa ge
• PROM (Programmable Read Only Memory): PROM stands for programmable ROM. It
can be programmed only be done once and read many. Unlike RAM, PROMs retain their
contents without the flow of electricity. PROM is also nonvolatile memory. The significant
difference between a ROM and a PROM is that a ROM comes with pre-written by the computer
manufacturer whereas PROM manufactured as blank memory. PROM can be programmed by
PROM burner and by blowing internal fuses permanently.
• EPROM (Erasable Programmable Read Only Memory): EPROM is pronounced ee-prom.
This memory type retains its contents until it exposed to intense ultraviolet light that clears its
contents, making it possible to reprogram the memory.
• EEPROM (Electrically Erasable Programmable Read Only Memory): EEPROM can be
burned (programmed) and erased by first electrical waves in a millisecond. A single byte of a
data or the entire contents of device can be erased. To write or erase this memory type, you
need a device called a PROM burner
The fundamental assumption of virtual memory is that programs do not have to entirely reside
in main memory when executed, the same way a program does not have to entirely fit in a cache,
in order to run. The concept of virtual memory has emerged primarily as a way to relieve
programmer from the burden of accommodating a large program in a smallmain memory: in the
early days the programmer had to divide the program into pieces and try to identify those parts
that were mutually exclusive, i.e.they had not to be present at the same moment in memory; these
pieces of code, called overlays, had to be loaded in the memory under the user program control,
making sure at any given time the program does not try toaccess an overlay not in memory.
Virtual memory automatically manages the transfer of pieces of code/ data between the disk
and main memory and conversely. At any moment of time, several programs (processes) are
running in a computer; however, it is not known at compile time, which will be the otherprograms
with which the compiled program will be running in a computer. Of course, we discuss here about
systems that allow multiprogramming, which is the case with most of today’s computers: a good
image for this is any IBM-PC running Windows, where several applications may be
simultaneous active. Because several programs must share, together with the operating system,
9|Pa ge
the same physical memory, we must somehow ensureprotection, that is we must make sure each
process is working only in its own address space, even if they share the same physical memory.
Virtual memory also provides relocation of programs; this means that a program can be loaded
anywhere in the main memory. Moreover, because each program is allocated a number of blocks
in the memory, called pages, the program has not to fit in a single contiguous area of the main
memory. Usually virtual memory reduces also the time to start a program, as not all code and
data has to be present in the memory to start; after the minimum amount has been brought into
main memory, the program may start.
Memory can be split into two main categories: volatile and nonvolatile. Volatile memory loses any
data as soon as the system is turned off; it requires constant power to remain viable. Most types of
RAM fall into this category. Nonvolatile memory does not lose its data when the system or device
is turned off. A number of types of memory fall into this category. The most familiar is ROM, but
Flash memory storage devices such as CompactFlash or Smart Media cards are also forms of
nonvolatile memory.
3.4.1. Volatility
Volatile memory is computer memory that requires power to maintain the stored information. Most
modern semiconductor volatile memory is either static RAM (SRAM) or dynamic RAM (DRAM).
SRAM retains its contents as long as the power is connected and is easy for interfacing but uses
six transistors per bit. Dynamic RAM is more complicated for interfacing and control, needing
regular refresh cycles to prevent losing its contents, but uses only one transistor and one capacitor
per bit, allowing it to reach much higher densities and much cheaper per-bit costs.
SRAM is not worthwhile for desktop system memory, where DRAM dominates, but is used for
their cache memories. SRAM is commonplace in small embedded systems, which might only need
tens of kilobytes or less. Forthcoming volatile memory technologies that aim at replacing or
competing with SRAM and DRAM include Z-RAM and A-RAM.
10 | P a g e
3.4.2. Volatility
Non-volatile memory is computer memory that can retain the stored information even when not
powered. Examples of non-volatile memory include read-only memory (see ROM), flash memory,
3D XPoint, most types of magnetic computer storage devices (e.g. hard disk drives, floppy disks
and magnetic tape), optical discs, and early computer storage methods such as paper tape and
punched cards. Forthcoming non-volatile memory technologies include FeRAM, CBRAM,
PRAM, SONOS, RRAM, racetrack memory, NRAM and millipede memory.
11 | P a g e