Chapter 1 Lecture Notes

Computer Components (Hardware) 

    CPU
        ALU
        CU
    Secondary Storage
    Memory
        RAM
        ROM (Read-Only Memory)
            bootstrapping
    Fetch-Execute Cycle
      DEF: CPU's repeatdly bringing in instructions from memory,
           decoding, and executing them.


Computer-User Interactivity (Software)

    Operating System
      DEF: software which provides an interface for the user.

    High-Level Language
      DEF: A more human-accessible means of coding instructions by programming
           in an arbitrarily defined language.
        -Compiler
          DEF: software that translates a high-level language program into
               machine language.
            -Syntax
               DEF: grammar rules of a programming language.
            -Object File
              DEF: file of machine-language instructions that is the output
                   of a compiler.
        -Linker
          DEF: resolves cross-references among object files.
        -Loader
          DEF: Copies executable file into memory; initiates execution of instructions.
  

Executing a high-level language program:

                           |----------------|
                           | Error Messages |
                           |----------------|
      You Create                   ^
           |                       |
           |                Compilation Failed
           V                       |
|---------------------|            |
| High-Level Language |       |----------|
| Source File         |------>| Compiler |
|---------------------|       |----------|                  |--------------------| 
                                   |                        | Other Object Files |
                                   |                        |--------------------|
                          Successful Compilation                       |
                                   |                                   |
                                   |          |-------------|          |
                                   |--------> | Object File |-----|    |
                                              |-------------|     |    |
                                                                  |    |
                                                                  V    V
                                                                |--------|
                                                           -----| Linker |                
                                                           |    |--------|    
                                                           |                   
                                                           V                   
                                                   |-----------------|
                                                   | Executable File |
                                                   |-----------------|
                                                           |
                                                           |
                                                    Run the executable
                                                           |
                                                           |
                                  |--------|           |--------|
  What is important to you -----> | Output |<----------| Loader |
                                  |--------|           |--------|


  BINARY REPRESENTATIONS (of numbers)

    Bases 
        10 
            10 digits 
        2 
            2 digits 
        16 
            16 digits (and letters)

    We will consider base 10 and base 2.

      Consider the places for base ten numbers
        nth...111111
          ^   ^^^^^^
          |   ||||||
          |   ||||||- ones         : 1 * (10 ^ 0)
          |   |||||- tens          : 1 * (10 ^ 1)
          |   ||||- hundreds       : 1 * (10 ^ 2)
          |   |||- thousands       : 1 * (10 ^ 3)
          |   ||- ten thousands    : 1 * (10 ^ 4)
          |   |- hundred thousands : 1 * (10 ^ 5) 
          |
          |---> : 1 * (10 ^ (n - 1))

      Now consider the places for base two numbers 
        nth...111111
          ^   ^^^^^^ 
          |   |||||| 
          |   ||||||- ones : 1 * (2 ^ 0)   =  1
          |   |||||- twos : 1 * (2 ^ 1)    =  2
          |   ||||- fours : 1 * (2 ^ 2)    =  4
          |   |||- eights : 1 * (2 ^ 3)    =  8
          |   ||- sixteens : 1 * (2 ^ 4)   = 16
          |   |- thirty-twos : 1 * (2 ^ 5) = 32
          | 
          |---> : 1 * (2 ^ (n - 1))


    Conversion of base 10 to base 2
 
        Base 10        Base 2

          1           00000001
          2           00000010 
          3           00000011 
          4           00000100   
          7           00000111 
          8           00001000
          13          00001101
          16          00010000
          63          00111111


  TWOS COMPLEMENT

    Thus far we have considered only positive numbers.  We must now consider
    negative numbers.  This requires a special representation of binary numbers: 
    Twos complement representation
       The only time to apply these steps are when the most significant bit is a 1
       because this indicates that the number is negative.  The most significant
       bit is the leftmost bit in the string of digits:
         For example : 1000, 1111, 1010 are all negative numbers.

       What interests us most is the conversion from twos complement representation
       (base 2) to base 10 numbers. We already have converted positive numbers, now
       consider the negative number conversion.
       
       Follow this algorithm (list of instructions)
         1) Take the complement of the current base 2 number.
         2) Add 1 to the complement.
         This results in a positive base 2 number which can be converted as above.

       Application:
       Convert the following twos complement numbers to base 10.
 
         Base 2     Complement        Add 1      Base 10

          0001          NA             NA          1
          0011          NA             NA          3
          0100          NA             NA          4
          0111          NA             NA          7
       
          0000          NA             NA          0

          1001         0110           0111        -7
          1010         0101           0110        -6
          1000         0111           1000        -8
          1111         0000           0001        -1


       We can add twos complement numbers as well (similar as adding 1 above).  This
       is done similarly as in base 10.  Consider
   
      -1 + 2 = 1 
  
               Base 2      Base 10

                1111          -1 
              + 0010         + 2
              ------         --- 
                0001           1  

        Note that the final 1 is not carried over since we restrict the number of
        bits we can use to represent numbers.

      -4 + 7 = 3  
 
               Base 2      Base 10 
 
                1100          -4  
              + 0111         + 7 
              ------         ---  
                0011           3 

        Again, the final 1 is lost because of 4 bits.  



  (Arithmetic) OVERFLOW

    Try and add the following 2 twos complement numbers using 4 bits.

       2 + 7 = 9  
  
               Base 2      Base 10  
  
                0010           2   
              + 0111         + 7  
              ------         ---   
                1001          -7
 
        Note the incosistency in this operation.  This situation is described 
        as arithmetic overflow.  Arithmetic overflow is defined as (DEF) a
        result of an operation being too large to be represented by the
        expression's data type.

  RANGE
   
    This brings about the idea of the range of numbers that can be represented
    by a certain number of bits.  Previously, we were able to represent 16 and 63,
    however, in the previous example I was not able to represent 8.  This is
    because the size of a number is dependent upon the number of bits we use.


    Given k bits we acquire the following ranges of numbers.

        Unsigned: 0...2^(k)-1 
        Signed: -2^(k-1)...2^(k-1)-1

    Note that with 4 signed bits we can represent 
               -(2 ^ (4 - 1))...2 ^ (4 - 1) - 1  
                         = -8...7

    Thus our previous overflow example is consistent with the number of bits
    used to represent the result.
  
    The following program illustrates overflow and the number of bits used 
    to represent integers.  It is not important that you understand how the
    program works, the output is what we are concerned with.

      #include <iostream.h>
      #include <values.h>    // Library may be compiler dependent

      int main()
      {
        int num = MAXINT;          // Maximum allowable integer.

        cout << num - 1 << endl;   // Print output to the screen
        cout << num << endl;
        cout << num + 1 << endl;
        cout << num + 2 << endl;

        return 0;
      }

      Output:
 
      32766
      32767
      -32768
      -32767

        Note:
           Range: -32768...32767
           -2^(k-1)...2^(k-1)-1
           k = 16 bits

Chris Alvin