/* CS 341 Spring 2002 */
/* Note segment 1 */
/* 17-Jan-2002 */
/* Taken by Apostolos Paul Pantazis */


--> Designing a Primitive CPU.
    VanOwmen Architecture ( please check for spelling..)
    ... It's John von Neumann, von Neumann Bio

    1. General Purpose memory: Can be thought as an array. A value is
       placed on an adress and with a read the value can be taken from
       the particular location. (you could imagine how a write would
       work).

    2. CPU (Central Processing Unit), talks to Memory, actually it is 
       bidirectional depending on whether the CPU is Reading or Writing
       to memory.

    3. I/0 (memory mapped I/O).


    Simple Diagram

    |-----| <------ A  |---|       |----|
    | MEM |            |CPU|-------|I/O |
    |-----| <------> D |---|       |----|
     
    Memory Bus : Between MEM and CPU
    I/O Bus: Between CPU && I/O

    CPU: Manipulates Memory and does Math. It is Built of 2 pieces:

         1. CU or the Control Unit.
         2. ALU or Aritmetic / Logic Unit.

    CU: Decides how values get shuffled around, what should happen next.
    ALU: Arithmetic and logical operations.

    How does CPU work?
    In a general purpose computer, Memory contains values and instructions
    that tell the CPU what to do. The CPU fetches and instruction and
    executes it (during this process it manipulates memory). When it is
    done with the particual instruction it will fetch the next
    one. generaly a sequential process.

    Machine Cycle (CPU)
     Fetch --> Decode --> Execute --> Store.

    Cache : Special purpose memory to solve problem of processor being
            much faster than memory.

    Often we prefer to do lots of I/O at one time. To get things out of 
    memory, CPU will be slowing the process down(Remember we are in a time
    machine here back in the day when memory was faster than CPU speed).
    The solution to this is DMA(Direct memory adress). During this process
    our data will flow around the CPU so the CPU can do something else.

    --> Consider a 16 bit computer (16 Bit refers to how wide the MEM Bus
        is and alos how wide things are inside the CPU)

        Instruction = just a word in memory that tells CPU what to do.

        Example:
        ADD, SUB, MUL, DIV ( aritmetic instructions) 
        LOAD, STORE (Memory Access)
    
        This computer will be a 1-adress computer, an accumulator (Just 1
        register). Each instruction will be encoded by 3 Bits, these bits
        are refered as the OPcode (operation code).


        ADD  --> 000
        SUB  --> 001
        MUL  --> 010
        DIV  --> 011
        LOAD --> 100
        STORE --> 101


        |-------------------------|
        |-----|-------------------|
          (1)       (2)

        (1): The opcode part 3 Bits
        (2): adress 13 Bits.

       This computer can adress a max of 16K Bytes (8K Words).

       The CPU will look at the Opcode. If the opcode says ADD, it will 
       fetch from memory the value and add it to its accumulator.

       Instructions look like a C program.
       a+=m[237] weer 237 is the adress.
       a/=m[17]. Lets consider this ex in more detail:
       From table above the Opcode is 011 for a divide.
       17 in Binary is : 0000000001001
       So:
       |---|-------------------|
       |011| 17 in binary      |
       |---|-------------------|

       LOAD --> a = m[13]
       STORE --> m[29] = a

       1-adress machine : Each instruction contains one adress.
       Machine code: the actuall 0 and 1's
       DIV 17 --> assembly code.
   
       Translate C code into accumulator code
   
       C statments: a = b + c;
                    d = a*a / e;

       If a corresponds to memory location 64
          b to 65
          c to 66
          d to 67
          e to 68

       Then:

       LOAD 64
       LOAD 65
       ADD  66
       STORE 64
       LOAD 64
       MUL 64
       DIV 68
       STORE 67

  
       These are note I have not including MSI and schematics.