Day 11
I. Last Time:
Hw #3 Posted Due!!!
Test Friday
A. ASCII Finished

B. IEEE754 format. to/from decimal
There is also a "double" (64-bit) format.
IEEE754 is only accurate to about 5-6 digits of decimal!

C. Endian Ness
      We think of computer memory as an array of bytes!!!
      1. How does a computer memory work:
         a. Can retrieve whole words - working with numbers
         b. Can also retrieve individual bytes - working with ASCII
         If we store a word and retrieve a byte, which end is which
      2. BIG-Endian: The "BIG" end of the word comes first in memory
         Many Workstations
      3. LITTLE-Endian: The "Little" end of the word comes first in memory
         Intel Based Machines
      4. SPIM - Conforms to the endianess of the underlying machine
      5. What this REALLY means to US - Sometimes Memory Dumps look BACKWARDS
         (As in one of the homework problems)
The problem comes when reading words of data that was stored as bytes
or by reading bytes of data stored as words.

   D. MIPS and Data Types:
32-bit types:
Integer: Signed, Unsigned
Float: IEEE-754
8-bit types:
Character
16-bit types are also used!

       Question: What is the meaning of 0x476F6F64
       Answer: What type of data is it?
       1. ASCII: "Good" 
       2. Unsigned 32-bit Big Endian:
             = 4+6*16+15*16^2+6*16^3+15+16^4+6*16^5*7*16^6+4*16^7
             = 738,872,887,701,363
       3. 32-bit Signed 2's Compliment Big Endian:
          It's positive - Same as above
       4. Unsigned 32-bit Little Endian:
          REAL order: 0x646F6F47
             = 7+4*16+15*16^2+6*16^3+15+16^4+6*16^5*4*16^6+6*16^7
             = 422,214,075,772,758
       5. 32-bit Signed 2's Compliment Little Endian:
          It's positive - Same as above  
       6. As IEEE-754 Floating Point (Big Endian):
          0100 0111 0110 1111 0110 1111 0110 0100
          Sign = 0 = Positive
          Stored Exponent = 1000 1110 = 8*16+14 = 142.
              Real Exponent = Stored - 127 = 15
          Significand = 1.110 1111 0110 1111 0110 0100
          1+2^-1+2^-2+2^-4+2^-5+2^-6+2^-7+2^-9+2^-10+2^-12+
            2^-13+2^-14+2^-15+2^-17+2^-18+2^-21
          = 1.87058687210083007812
          Result = significand*2^Real Exponent = 
          = 1.87058687210083007812*2^15
          = 61295.39062499999999983616

II. New Stuff:   
A. MIPS Machine:
       Instructions in MIPS do 1 of 3 things:
Data Movement:
Move data around:
Register<->Memory
Register<->Register
Data Manipulation:
Actually Change/calculate data
ALWAYS register(s)->Register
Ex: ADD
Control:
Decision Making:
"if" statements
"whiles"
These are called "Branching"
because the "path" of instructions
that the program takes changes or branches
off.

       Highlights:
           32, 32-bit GENERAL PURPOSE registers
           (General Purpose - Few registers have special 
               meaning to the hardware. They DO have special 
               meaning to the programmer though!)

           Data Manipulation can ONLY be performed on the 
           32 values available in registers - If you need to 
           work with larger amounts of info. you must "shuttle"
           data to/from memory via the data movement commands.
           (This is typical of RISC Machines)

           Co-Pro - In MIPS a seperate Co-Processor deals with 
           some types of arithmatic. (Float Point) and interupts.

     The Challenge: Write a program to do something usefull given 
        these constraints/rules. It's a challenging puzzle and will
        give us some insight into:
            A. How the CPU works
            B. How to write better programs even in higher level
               languages
            C. Insight into the design/constraints of some higher 
               level languages.                


       B. Register Names: Registers have both a symbolic and a numeric Name
           Numeric name: $<number>
            $0  - $zero - Register[0]
            $1  - $at   - Register[1]
            $2  - $v0   - Register[2]
            //    v1,a0-a3,
            $8  - $t0   - Register[8] "T emporaries"
            $9  - $t1   - Register[9]
            ...
            $15 - $t7   - Register[15]
            $16 - $s0   - Register[16] "S tatic"
            $17 - $s1   - Register[17]
            ...
            $23 - $s7   - Register[23]
            $24 - $t8   - Register[24]
            $25 - $t9   - Register[25]
          We'll only work with the "s-registers" today

          Names established to enforce usage conventions so 
          different assembly programmers can work together.
          We'll discuss these usage conventions next week.
          They are established to ensure that modules written
          by different programmers will successfully work 
          together. They are NOT enforced by the hardware but 
          they WILL be enforced by me.
            
     C. Commands: Data Manipulation - Simple Math
        Basic Format:
           add dest_reg, srca, srcb    # dest_reg=srca+srcb
        I want to add what's in register $s4 to what's in $s5 
        and store the result in $s3:
           add $s3,$s4,$s5
        (Addition is commutative so we could also go with:
           add $s3,$s5,$s4)
        Also, we could use the register NUMBERs rather than names:
            add $19,$20,$21

D. R-Format Instructions
       R-format instructions - 
              Working between registers only - all data comes 
              from a register              
     
        R-Format:
          6 bits  5 bits 5 bits 5 bits 5 bits 6 bits
          op code   rs     rt     rd    shamt func
          The op-code and function code together determine 
          the instruction. rs, rt and rd specify the registers 
          to use. Ignore shamt for the moment (assume 0)
          add inst: R-Format, op=0, func=32d = 10 0000b
          add $s1, $s2, $s4
          RD = $s1, RS=$s2, RT=$s4
          NOTE: NOT in the order of the written instruction!!!!
          s1 = $17 = 1 0001b
          s2 = $18 = 1 0010b
          s4 = $20 = 1 0100b
          NOTE: 5-bits allows you to pick a number from 0-31. 
                I.e. to pick one of the 32 registers.
          op = 00 0000b
          rs = 1 0010 b
          rt = 1 0100 b
          rd = 1 0001 b
          shamt = 0 0000b
          funct = 10 0000b
          00 0000 | 1 0010 | 1 0100 | 1 0001 | 0 0000 | 10 0000
          0000 0010 0101 0100 1000 1000 0010 0000
          =0x02548820
          So, now when I give you a word in binary it can be interpreted
          at least 5 ways: ASCII text, and Instructions, a signed number, 
          an unsigned number, and a floating point number.
          Note that this is JUST a "number" in binary - This is
          what Von Neumann had in mind for the stored program concept.

          These instruction formats allow the "control" to read back
          and "decode" the instruction to control the ALU and datapath. 
          We'll discuss this in the coming chapters.

E. Subtraction
Basic Format:
           sub dest_reg, srca, src_regb    # dest_reg=srca-srcb

        I want to subtract register $s5 from register $s2 and store the
        result in register $s4:
           sub $s4,$s2,$s5 # s4=s2-s5

    F. More complex equations:
           WE must perform operations in the proper order and 
           store temporary results - these are things that usually
           the compiler does for us and we take for granted...
           f = (g + h) - (i + j)
           Assume that f in in register s0
                       g is in register s1
                       h                s2
                       i                s3
                       j                s4

           What do we do?
                Break into smaller operations - just as if we were
                solving it by hand: 
                     x=g+h
                     y=i+j
                     f=x-y
                Pick a place for x and y. Be carefule not to trounce
                another register already being used: 
                    $s5 and $s6 respectively
           add $s5,$s1,$s2 # x=g+h
           add $s6,$s3,$s4 # y=i+j
           sub $s0,$s5,$s6 # f=x-y = (g+h)-(i+j)

 III. Next Time:
A. Quiz & Return/Discuss HW
B. Return HW/Notes on HW
People and WWII influence
Apple/Windows people and PC era
SUN (dot in dot com)
Mitnick/Legality
Bushnell/entertainment
Moore - capacity doubles every 18 months
Amdahl - Machine is dominated by slowest part
HD man and Base Cost (materials)
C. Memory & Arrays!