Comp 255 - Computer Organization - Memory and I/O



"A computer is an electronic (?) device operating under control of instructions stored in its own memory unit that
  1. accepts data (input)
  2. processes data arithmetically and logically
  3. displays information (output) from the processing and/or
  4. stores the results for future use"

Memory

Addressable Memory can be thought of a linear sequence of numbered same sized "cells". Each cell has the same number of bits.
  +-----+
  | MAR |  selects cell address
  +-----+
     |
        +------+       +-------+
   0000 | 1234 | <-+-> | M B R |  reads/writes    
        +------+   |   +-------+  cell contents 
   0001 | 7700 | <-|
        +------+   |    
   0002 | 0000 | <-|       
        +------+   |
   0003 | AAFF | <-|
        +------+   |
   0004 | 0100 | <-|
          ....     |
                   |
        +------+   | 
   FFFF | 0000 | <-+
        +------+
We distinquish between the address of a cell and the contents of a cell. Access to memory is controlled by two registers, the Memory Address Register (MAR) and the Memory Buffer Register (MBR). An "address" placed in the MAR will select a cell of memory. A memory read will cause the contents of that cell to be copied to the MBR; a memory write will cause the contents of the MBR to be copied to the cell.
Example of "Big Endian" vs "Little Endian" Addressing (See Fig 2-12). A record consisting of the 12 byte string "JIM SMITH " following by two 32 bit integers 21 (15h) and 260 (104h) is stored in a block of 20 bytes.

Problems occur if we copy a record from a Big Endian computer to a Little Endian computer.

          Big  Endian                    Little Endian
    +-----+-----+-----+-----+      +-----+-----+-----+-----+
 0  |  J  |  I  |  M  |     |      |     |  M  |  I  |  J  |  0 
    +-----+-----+-----+-----+      +-----+-----+-----+-----+
 4  |  S  |  M  |  I  |  T  |      |  T  |  I  |  M  |  S  |  4
    +-----+-----+-----+-----+      +-----+-----+-----+-----+
 8  |  H  |     |     |     |      |     |     |     |  H  |  8
    +-----+-----+-----+-----+      +-----+-----+-----+-----+
12  | 0 0 | 0 0 | 0 0 | 1 5 |      | 0 0 | 0 0 | 0 0 | 1 5 | 12 
    +-----+-----+-----+-----+      +-----+-----+-----+-----+  
16  | 0 0 | 0 0 | 0 1 | 0 4 |      | 0 0 | 0 0 | 0 1 | 0 4 | 16
    +-----+-----+-----+-----+      +-----+-----+-----+-----+
If the Big Endian formated record on the right is copied to a Little Endian computer, the record on the left below results. Note that the integers are wrong.

If we copy and swap the bytes within a 32 bit word (see below right), the string comes out backward.

 
     
                                      
      Xfer Big to Little                 Xfer and Swap       
    +-----+-----+-----+-----+      +-----+-----+-----+-----+
    |     |  M  |  I  |  J  |  0   |  J  |  I  |  M  |     |  0 
    +-----+-----+-----+-----+      +-----+-----+-----+-----+
    |  T  |  I  |  M  |  S  |  4   |  S  |  M  |  I  |  T  |  4
    +-----+-----+-----+-----+      +-----+-----+-----+-----+ 
    |     |     |     |  H  |  8   |  H  |     |     |     |  8
    +-----+-----+-----+-----+      +-----+-----+-----+-----+
    | 1 5 | 0 0 | 0 0 | 0 0 | 12   | 0 0 | 0 0 | 0 0 | 1 5 | 12 
    +-----+-----+-----+-----+      +-----+-----+-----+-----+  
    | 0 4 | 0 1 | 0 0 | 0 0 | 16   | 0 0 | 0 0 | 0 1 | 0 4 | 16
    +-----+-----+-----+-----+      +-----+-----+-----+-----+
        integers wrong                     string wrong

Error Detecting/Correcting Codes

Designing a single-bit error correcting code

There is a lower bounds for the size (i.e. total number of bits needed). Assume m code bits and r check bits for n bits total. Each of the 2^m legal codes (there are m code bits) has n illegal code words at distance 1 from it. So each legal codeword takes up (n+1) codewords (itself plus n single bit changes) for a total of (n+1)*2^m code word in all. Thus (n+1)*2^m <= 2^n. Since n = m+r we obtain (m+r+1) <= 2^r. Given m, this puts a lower bound on the number of check bits r.

Example If m = 16 then r = 5 (16+5+1<=2^5) so we need a 21 bit codeword. (Note r = 5 works for values of m up to 26). We number the bits of our code word 1 - 21 and we make bits 1, 2, 4, 8, and 16 (note powers of 2)the check bits. The other 16 bits are data bits. Each check bit serves as an (even) parity bit for a special "parity" sub-group of the 21 bits.

The diagram below makes this easier to see.
                    1 1 1 1 1 1 1 1 1 1 2 2  <- bit number 
  1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 
  - - - - - - - - - - - - - - - - - - - - - 
  x x d x d d d x d d d d d d d x d d d d d  <- code word 
  - - - - - - - - - - - - - - - - - - - - -   
  1   1   1   1   1   1   1   1   1   1   1  <- Group 1 bits
    2 2     2 2     2 2     2 2     2 2      <- Group 2 bits
        4 4 4 4         4 4 4 4         4 4  <- Group 4 bits
                8 8 8 8 8 8 8 8              <- Group 8 bits
                                h h h h h h  <- Group 16 bits

   x - denotes check bit
   d - denotes data bit

   Note: The sum of the Group numbers for each bit 
         equals its bit number.
There is a formula that assigns each bit to a parity group. Express the bit number as a sum of powers of 2. The bit belongs to those groups. For example 11 = 8+2+1 so bit 11 belongs to groups 1, 2, and 8. This is critical since it permits any single-bit error to be easily identified by summing the parity group numbers (1,2,4,8,or 16) which fail to have even parity. For example, if groups 1, 2, and 8 failed to have even parity, bit 11 is the error bit. 

Cache Memory

Cache memory is special high speed memory usually located on or very near the processor chip. When a word is fetched from memory, it (along with any words close by) is loaded in cache. If the same word is needed again, it's quicker to locate it in cache. The locality princple is the observation that memory references over a short period of time tend to come from the same location in memory. If a word is accessed k times over a short time inteval, it will require one reference to slow memory and k-1 references to cache. We can quantitize this as follows.
Let c = cache access time.
    m = memory access time
    h = hit ratio, fraction of all references satisfied out of cache
        that is h = (k-1)/k then
If on a cache miss the word is first loaded into cache and then the word is read from cache (non Load Through), the mean access time of a word is c + (1-h)m where (1-h) is sometimes called the miss ratio. Example If cache access time c is 10 nsec, memory access time m is 200 nsec and h, the hit ratio is 0.9, the mean access time is
        mean access = 10 nsec + 0.1 * 200 nsec = 30 nsec

Otherwise, with Load Through (on a cache miss the word is loaded in parallel to cache and the CPU) the mean acces time of a word is h*c + (1-h)*m. This would change the mean access time in the above example to 29 nsec.

        mean access = 0.9 * 10 nsec + 0.1 * 200 nsec = 29 nsec

Issues in Cache Design

Return to Comp 255 Home Page