MIPS code examples

Copy over these files into your cs75 subdirectory:

		cp -r ~newhall/public/cs75/mipsfiles .
		

  1. We are going to start by looking at logical.mips, and complete the MIPS code that is missing from this file. Remember that you need to implement short-circuting code for logical operators. For example, here is one way to implement short circuiting for logical AND:
               AST:    AND
                      /   \
                   expr1  expr2
    
    		expr1 AND expr2: 
    			(1) generate code to evaluate expr1
    			(2) generate code to test if expr1 is false
    					branch to later code that will set result to 0
    					(this is the short-circuting code that skips over code that evaluates expr2)
    			(3) generate code to evaluate expr2
    			(4) generate code to test if expr2 is false
    					branch to later code that will set result to 0 
    			(5) generate code to set result to true (1) and branch over setting result to false code 
    			(6) generate code to set result to false (0) (this is the branch target of (2) and (4) 
    			(7) generate label for true branch target that skips over (6) code
    		

  2. Next, we are going to try finishing the code for the while loop in while.mips. This involves implementing flow control instructions much like how we implmented the short-circuting code for AND and OR.
         AST:    WHILE
                /     \ 
               expr    stmt
    		

  3. Then lets try function.mips. Here we need to generate function call code in main where we pass a single parameter and get the return value from the called function, and code in function blah that modifies a parameter value and returns a value to the caller.
         AST:      FUNC_CALL             RETURN               
                   /   |                   |
                expr1 expr2 ...          expr