CS75 Lab for Friday March 27

MIPS and SPIM
We are going to practice writing some MIPS assembly code by hand and running it in SPIM.

On-line SPIM and MIPS references are available under the "On-line Resources" section of the CS75 homepage: Links to MIPS and SPIM references. We are going to start by looking at the "brief intro to MIPS and SPIM" link.

In addition, two copies of the SPIM Reference Manual are in the CS labs, bound with yellow covers. Please leave these in the main and/or overflow labs.


Create a new file called simple.mips into which we will write our first MIPS program.
  1. All SPIM assembly files will start with the following:
               .data
    _newline_:
               .asciiz "\n"
               .text
               .globl main
    
    _newline_ is program data, that is the string "\n" that will used for writeln statements, and the only global text symbol is main (main will be a label that corresponds to the first instruction in main).
  2. We are going to write SPIM code for some simple programs that consist of some statements in a single function main. To do this we need to implement main's prolog code to set up its stack frame next. We will ignore saving callee saved registers for now and just save the FP and the RA and adjust FP and SP for main's stack frame which will look like this:
    
      SP ---------> saved RA value   # top of main's stack frame
                    saved FP value
      FP --------->                  # bottom of main's stack frame (the caller's SP)
    
  3. Now we are going to generate the body of the main function for the following program:
    int main() {
      write 6;
    }
    
    write can be implemented using the SPIM system call print_int.
  4. finally, we are going to implement main's epilog code. In the epilog, we need to restore the caller's stack frame using the current FP value, and the saved FP value (if we had save callee saved registers to the stack, we would also restore their values here). We then restore the RA value that was saved in main's stack frame and generate a jr instruction to jump to the value in the $ra register.
  5. okay, let's try running our program in xspim:
    $ xspim simple.mips 
    

  6. After we get this working, try some of the hw4 problems.