Computer Sciences Dept.

CS/ECE 354 Machine Organization and Programming

Fall 2008 Section 1
Instructor Mark D. Hill
TAs Mark Liu & Somayeh Sardashti
MIPS RISC Conventions

Register Usage Conventions


Purpose

The purpose of this document is to clarify the procedure/register usage conventions you are expected to follow to get the most credit for the program that implements functions/procedures.

Class has not presented the MIPS RISC conventions for procedure linkage and register usage exactly as they are stated in the MIPS RISC Architecture manual. So, what follows are not MIPS RISC conventions at all.

Conventions to Follow

  1. Correct usage of registers. All code may use registers $8-$25. All of registers $8-$25 are designated as callee (child) saved. Therefore, before any function uses a register, it must save the value (on the stack, in the function's activation record). And, before returning, the function must restore the saved values.
  2. Parameter location. All parameters are passed on the stack.

    The parent allocates activation record space for any and all parameters, and places the actual parameters into that activation record space.

    The child retrieves and uses the formal arguments.

  3. Size of activation record. There are two choices for the size of a procedure's activation record. A compiler would either allocate an activation record that is the same size for all functions (and it would contain extra, unused space for many functions), or it would allocate an activation record that is exactly the correct size for a function. This size would be different for different functions.

    Make activiation records the exact size needed for the function.

Here is a diagram indicating the contents of activation records. Note that the ordering of data within the activation record will be the same for all functions. Here are activation records for functions A and B. Assume that function A calls function B, and passes 5 parameters. Assume that function B calls function C, and passes 1 parameter.

        |                | smallest addresses
        |----------------|
        |                |
        |================|
        | P1 (B passes   |---
        |     to C)      |   |
        |----------------|   |
        | any regs       |   |
        | used by B: $8  |   |
        |----------------|   |
        |            $9  |   |
        |----------------|   |---- function B's activation record
        |            $10 |   |
        |----------------|   |
        |            etc.|   |
        |----------------|   |
        | copy of $ra    |   |
        | B's return addr| --|
        |================|
        | P1 (A passes   |---
        |     to B)      |   |
        |----------------|   |
        | P2 (A passes   |   |
        |     to B)      |   |
        |----------------|   |
        | P3 (A passes   |   |
        |     to B)      |   |
        |----------------|   |
        | P4 (A passes   |   |
        |     to B)      |   |
        |----------------|   |
        | P5 (A passes   |   |
        |     to B)      |   |
        |----------------|   |---- function A's activation record
        | any regs       |   |
        | used by A: $8  |   |
        |----------------|   |
        |            $9  |   |
        |----------------|   |
        |            $10 |   |
        |----------------|   |
        |            etc.|   |
        |----------------|   |
        | copy of $ra    |   |
        | A's return addr| --|
        |================|
        |                |
        |----------------|
        |                |

 
Computer Sciences | UW Home