Memory/Register File Interface

Tom Kelliher, CS 240

Jan. 27, 1999

Administrivia

Announcements

Everyone should ``try'' out their accounts.

Assignment

To be handed out.

From Last Time

Operands, registers.

Outline

  1. Memory addressing.

  2. Instruction formats.

  3. Immediate operands.

Coming Up

Branches. Finally!

Memory Addressing

  1. The programming model:

  2. Datapath flow for arithmetic instructions.

  3. HLLs have complex data structures such as arrays and structs. How are they handled? The register file is a compiler/assembly language programmer controlled cache.

  4. Code segment, data segment.

  5. Data transfer instructions: load, store. operands: memory address, register.

  6. Actual MIPS instructions: lw, sw. Datapath flow. Small example:
             # int a, b, c;
             # c = a + b;
             # Assume a is pointed to by $s0 and that b and c are in
             # successive memory locations.
    
             lw $t0, 0($s0)
             lw $t1, 4($s0)
             add $t0, $t0, $t1
             sw $t0 8($s0)
    
    Base, offset addressing.

  7. MIPS memory is byte addressable, so word addresses differ by 4:

    Endianess.

  8. Compile the following:
    g = h + A[8];
    
    where g is in $s1, h is in $s2, and the base address of A, an array of 100 words, is in $s3.

    Compile each of the following:

    A[12] = h + A[8];
    
    A[j] = h + A[i];
    

Notes:

  1. Base, offset addressing, using constant offsets, is similarly useful for accessing members of structures:
    struct foo {
       int a;
       char b;
       int c;
    };
    

             lw $t0, 0($s0)   # load foo.a.
             lb $t0, 4($s0)   # Etc.
             lw $t0, 8($s0)
    

  2. Variables in registers are simpler to use and faster than variables in memory. Compilers must be clever in optimizing register use. Spilling registers.

Instructions at the Machine Level

(Section 3.4)

  1. What does a real instruction look like?

  2. Consider an add instruction. What has to be there? What about a memory access instruction?

  3. Bits per instruction? Variably-sized instructions? Variable field positions?

  4. Design principle 3: Good design demands good compromises. One instruction width, different formats. Overlap (maintain regularity) where possible.

Instruction formats for instructions we've seen so far:

Field meanings?

Immediate Operands

  1. Operand types (addressing modes) we've seen so far: registers, memory.

  2. What about constants? Where have we already seen immediates? Arithmetic example:
             addi $t0, $s0, 8   # An immediate operand.
    

  3. Immediate operand: found within the instruction itself.

  4. Small immediates occur frequently, so...

  5. Design principle 4: Make the common case fast.

  6. But, how do I load a 32-bit immediate? lui followed by addi (whoops, sign extension) or ori:
             lui $s0, 0x5555
             ori $s0, $0, 0xaaaa
    

  7. How does the assembler manufacture 32-bit immediates for us? Register $at.

  8. Programmer conventions. ``Enhanced'' assembly language. Simplicity.



Thomas P. Kelliher
Tue Jan 26 09:15:46 EST 1999
Tom Kelliher