May want to bring a second laptop for jassem

- Assembler: Computer organization & stack frames.
- Goal to teach how assembly code is generated by a compiler.  Not precise, but intuitive.
- Made-up RISC with 4 byte pointers and no floating point.  YAY!!

Registers:
    8 general purpose:
      - 4 bytes and can be read/written
      - r0 through r4.
      - sp, fp, pc
  
    3 read-only: g0, g1, gm1

    Special inaccessible ones:

       IR - holds the current instruction
       CSR - Information about the previous instruction

Instruction Cycle:

   - Decode & execute instruction in IR
   - Determine the next instruction & update the pc
   - Load the next instruction into the IR

Stuff

   Instructions are four bytes, and are stored in memory.  pc = current instruction.
   If an instruction is not a control instruction, pc += 4 each instruction cycle.

What RISC means in this context: Only loads and stores touch memory.

Three types of instructions for now:

1. Memory <-> Memory: 
  
   ld mem -> %reg
   st %reg -> mem

5 ways to address memory:

   Global variable
   [reg]
   [fp+x]
   [sp]--
   ++[sp]

2. Register <-> Register

   mov %reg -> %reg
   mov #val -> %reg

   add %r1, %r2 -> %r3     -- They can be the same.
   sub
   mul
   idiv
   imod

   Arithmetic on the stack pointer: 

   push #val
   pop #val

3. Control:

   jsr a
   ret

4. .globl directive.

The address space -- see  txt/Address.txt.  No heap in this world.

Simple Compiled Code.  Make the TEGWar analogy.

Start with p1-g.c    Show how dumb it is, and how you could easily make
it faster.  Stress that we don't optimize in this class.
Bust out jassem.

Next p1.c -- talk about how the stack works with sp & fp.  Show how push 8
can be used to allocate i and j.  By convention, j is on the bottom.

Write the code.  Then walk through with jassem.

------------------------------------------------------------

If time -- question about memory. test1 breaks the malloc.
test2 breaks the stack.