Chapter 4
Memory Organization
                      1
                      Introduction
• Memory Unit
   – an essential component in any general purpose computer
     since it is needed to store programs and data.
• A memory unit that communicates directly with the CPU is
  called main memory.
• Memory unit that provide backup storage is called auxiliary
  memory.
• Auxiliary memory devices are used to store system
  programs, large data files and other backup information.
  Only programs and data currently needed by the processor
  reside in main memory.
• All other information is stored in auxiliary memory and
  transferred to main memory when needed.                 2
                   Memory Hierarchy
• To obtain the highest possible access speed while
  minimizing the total cost of the memory system
• Consists of all storage device in a computer system
  (auxiliary, cache, main , high speed registers and processing
  logic)
                                                           3
Memory Hierarchy (cont…)
                           4
Memory Hierarchy (cont…)
                           5
                         CPU Registers
• CPU Register - also known as Internal Processor Memory.
• The data or instruction which has to be executed are kept in these
  registers.
• A CPU register is a quickly accessible location available to a
  computer's processor.
• Registers usually consist of a small amount of fast storage, although
  some registers have specific hardware functions, and may be read-
  only or write-only.
                                                                  6
                     Cache Memory
• Memory that lies in between main memory and CPU
• Holds those parts of the program and data that are most
  heavily used
   – increases the overall processing speed of the computer by
     providing frequently required data to the CPU at a faster
     speed.
                                                          7
                 Main Memory (RAM)
• Memory unit that communicates directly with CPU
  Programs and data currently needed by the processor reside
  here
• It is also known as primary memory.
• It is of two type
   – Random Access Memory (RAM) and
   – Read Only Memory (ROM)
                                                        8
                    Auxiliary Memory
• The Most common auxiliary memory devices used in
  computer system are magnetic disk and tapes.
• Other components used, but not as frequently, are
   – magnetic drums,
   – magnetic bubble memory, and
   – optical disks
• The average time required to reach a storage location in
  memory and obtain its contents is called the access time.
• In electromechanical devices with moving parts such as
  disks and tapes, the access time consists of seek time
  required to position the read-write head to a location and a
  transfer time required to transfer data to or from the devices.
                                                             9
            Memory Management System
• Many operating system are designed to enable the CPU to
  process a number of independent programs concurrently -
  known as multiprogramming.
• Sometimes a program are too long to be accommodated in
  total space available in main memory.
• A program with its data normally resides in auxiliary
  memory.
• When the program or a segment of program is to be
  executed, it is transferred to main memory to be executed by
  the CPU.
• The part of the computer system that supervise the flow of
  information between auxiliary memory and main memory is
  called the memory management system.                    10
                      Memory Types
1. Sequential Memory
• A class of data storage device that read their data in
  sequence
• Are usually a form of magnetic memory
• Typically used for secondary storage in general-purpose
  computers due to their higher density, resistance to wear and
  non-volatility
• Eg: hard disk, CD-ROMs, magnetic tapes, etc
2. Random Access Memory (RAM)
• Is a form of computer data storage
• Allows stored data to be accessed in any order
• Associated with volatile types of memory
                                                           11
                      Main Memory
• Basic memory of the computer
• Temporary memory except ROM
• Faster for read write operation
• Expensive internal memory so not portable.
1. RAM
   – Volatile memory.
   – Stores information required during processing
   – Has two two types
      • Static RAM(SRAM) and
      • Dynamic RAM(DRAM)
                                                     12
                     Types of RAM
            SRAM                            DRAM
• Does not lose its content      • Loses its content after few
  until computer is turned off     seconds
• Information is stored in       • Information is stored in the
  form of voltage                  form of charge
• faster                         • slower
                                                             13
               Read only Memory (ROM)
• ROM stands for read only memory, a solid-state
  semiconductor memory that can only read data stored in
  advance. Its characteristic is that once the data is stored, it
  can no longer be changed or deleted.
• It is usually used in computer or other electronic devices,
  and even if the power is turned off, the data will not
  disappear.
                                                            14
                       Types of ROM
1. MROM - Mask Read Only Memory
• It is inexpensive and is the very first ROM which is hard wired
   device that contains a pre-programmed set of data or
   instructions.
2. PROM - Programmable Read Only Memory
• It can be written only once by a user.
• PROM is manufactured as a blank memory, while the ROM is
   programmed during the manufacturing process.
• The user buys a PROM, the user will need a special device
   called a PROM programmer or PROM burner to write the
   desired data onto the blank PROM chip.
• The process of programming a PROM is sometimes called
   burning the PROM.
• The memory can be programmed just once after manufacturing 15
                 Types of ROM (cont …)
3. EPROM - Erasable Programmable Read Only Memory
• It is a special kind of read only memory chip that has the
   opportunity to erase the programmed data, which the feature can
   be seen from its name.
• The programmable read-only memory can be programmed to
   write data with high voltage, and the data remains until it is
   exposed to ultraviolet light for lasting up to 10 minutes or
   longer.
4. EEPROM - Electrically Erasable and Programmable Read
   Only Memory
• It can be erased and reprogrammed about 10,000 times. Both
   erasing and programming take about 4 to 10 milliseconds.
• users can selectively erase and program any location and it can
   be erased one byte at a time instead of being erased the entire
                                                              16
                 Types of ROM (cont …)
5. Flash Memory
• Flash memory (flash) is a modern type of EEPROM.
• Flash memory can be erased and rewritten faster than ordinary
   EEPROM, and newer designs has the feature that is very high
   endurance (exceeding 1,000,000 cycles).
• Except these types, there are other types of non-volatile memory
   including optical storage media, such as 
    – CD-R and
    – CD-RW
                                                             17
                        RAM chip
• Used for communication with the CPU if one or more
  control inputs.
• requires 7-bit address and an 8-bit bidirectional data bus.
• chip select (CS) are for enabling the chip.
                                    •When CS1=1 and (CS2)’=0,
                                    the unit in operation.
                                    • High impedance state
                                    indicates open circuit.
                                    • When CS1=1 and (CS2)’=0,
                                    the memory is places in a R/W
                                    mode.
                                    • When the RD input is
                                    enabled, the content of the
                                    selected byte is placed into the
                                    data bus.
                                                                18
                        ROM Chip
                               • A ROM chip is
                                 unidirectional.
                               • 9 address lines to address 512
                                 bytes.
                               • Chip select CS1=1 and
                                 (CS2)’=0 for the unit to
                                 operate.
                               • Otherwise, the data bus in a
                                 high-impedance state.
The RAM chips have 128 bytes and need seven address lines.
The ROM chip has 512 bytes and needs 9 address lines         19
How to select chips?
                       20
Memory Connection to the CPU
                               21
                  Associative Memory
• When a memory unit is accessed by content rather than data
  address, the memory is referred to as associative memory
  or content addressable memory(CAM).
                          Argument Register : It contains the
                          word to be searched.
                          Key Register K : This specifies which
                          part of the argument word needs to be
                          compared with words in memory.
                                                            22
Associative Memory (cont …)
                              23
                      Cache Memory
• A typical computer program flows in a straight-line fashion
  with program loops and subroutine calls encountered
  frequently.
• Analysis of a large number of typical programs has been
  shown that the reference to memory at any given interval of
  time tend to be confined within a few localized areas in
  memory.
• This phenomenon is known as the property of locality of
  reference.
• 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 program.
• Such memory is known as Cache memory.                    24
               Cache Memory (cont …)
• The Performance of cache memory is frequently measured
  in terms of a quantity called hit ratio.
• When the CPU refers to memory and finds the word in
  cache, it is said to produce a hit.
• If the word is not found in cache, it is in main memory and
  it counts as a miss.
• No. of hits = number of successful cache memory
  references.
• No. of Misses = number of unsuccessful cache memory
  references.
                                                        25
                  Cache Memory (cont …)
• 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.             26
                 Cache Memory (cont …)
Characteristic of Cache Memory
• The basic characteristic of cache memory is its fast access time.
• The transformation of data from main memory to cache memory is
  referred to as a mapping process.
• Three types of mapping procedures are:
   – Associative Mapping
   – Direct Mapping
   – Set-associative Mapping
                                                              27
                   Associative Mapping
• The fastest and most flexible cache
  organization uses an associative
  memory.
• The associative memory stores both
  the address and content (data) of
  the memory word.
• If    the    address    is    found
  corresponding     data     is   read
  otherwise main memory is accessed
  for the word.
• It is expensive compared to
  random-access memories because
  of the added logic associated with
  each cell.                             28
                     Direct Mapping
• The n-bit memory address is divided into two Fields:
   – k-bits for the index field and
   – 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.
• Each word in cache consists of the data word and its
  associated tag.
• When a new word is first brought into the cache, the tag bits
  are stored alongside the data bits.
• When the CPU generates a memory request, the index field
  is used for the address to access the cache.            29
                Direct Mapping (cont …)
• The tag field of the CPU address is compared with the tag in
  the word read from cache.
• If the two tags match, there is a hit and the required word is
  read from cache otherwise it is read from main memory.
                                                           30
Direct Mapping (cont …)
                          31
Direct Mapping (cont …)
                          32
               Set- Associative Mapping
• In Direct mapping, every time a miss occurs, an entire block
  of words must be transferred from main memory to cache
  memory.
• Another disadvantage of direct mapping is that two words
  with the same index in their address but with different tag
  values cannot reside in cache memory at same time.
• A third type of cache organization, called set-associative
  mapping, in which each word of cache can store two or
  more words of memory under the same index address.
• Each data word is stored together with its tag and the
  number of tag-data items in one word of cache is said to
  from a set.
                                                         33
Set- Associative Mapping (cont …)
                                    34
                      Virtual Memory
• In a memory hierarchy system, program and data are first stored
  in auxiliary memory.
• Portion of a program or data are brought into main memory as
  they are needed by the CPU.
• Virtual Memory is a concept used in some large computer
  systems that permit the user to construct programs as though a
  large memory space were available, equal to the totality of
  auxiliary memory.
• A virtual memory system provides a mechanism for translating
  program-generated addresses into correct main memory
  locations.
• An address used by a programmer will be called a virtual
  address, and set of such addresses the address space.
• An address in main memory is called a location or physical 35