CSE 378 - Autumn 2002

Machine Organization and Assembly Language Programming

Useful Links
SMOK home Component Reference Turnin Form

Homework 5: SMOK MIPS Design and an Introduction to SMOK
Due Wednesday, November 13

Purpose:

This assignment puts together all the pieces of the CPU microarchitecture: instructions, data path, and control. You will learn how to design the microarchitecture of a real processor. It is also an introduction to the SMOK design tool, which allows you to design and test architectures at the register transfer level. Finally, since it requires you to write a procedure in MIPS assembly, it will also reinforce the mechanics of using procedure stack frames.

For this assignment, you should work in teams of two and hand in one homework for the two of you. Start now to find a partner. Both of you should work on both parts, so that you both get experience in designing a microarchitecture and working in the SMOK environment. The next assignment is also in teams, but you'll need to partner up with different person for that one.

Tasks:

Task 1: You are to build a single­cycle, small­scale MIPS microprocessor. This will be just like a commercial MIPS microprocessor (the R2000 vintage), except that you will implement only a handful of instructions, and you won't have to pipeline the machine (although you may think about how to do that, since this will be Homework #6). For this assigment the execution of each instruction will happen in one long clock cycle.

Task 2: Write a recursive function that calculates the n'th Fibonacci number. This function Fibonacci(i) will return an integer. You are to write this function first in MIPS assembly language, and then you are to hand assemble or use Spim to assenble your code into binary form. You will then execute this code on the machine you build in Task 1. Because of this you will have to write this function using only the set of instructions you actually implement in Task 1, but these should be enough.

The Details:

  1. We are going to use the latest version of SMOK, which executes on Windows only. This version can be downloaded from "http://www.cs.washington.edu/homes/zahorjan/homepage/Tools/SMOK/". Please use the latest version since it has been updated specifically for our class.

  2. The format of the instructions for your machine follow the real MIPS encoding format (R­type, I­type and J­type). In addition, just like the real MIPS architecture, your machine will have 32 integer registers, and follow the MIPS register conventions.

  3. The absolute reference for any details with this assignment is the real MIPS documentation, and any other documentation on the real MIPS microprocessor (unless otherwise explicitly modified in this handout, or we tell you otherwise). Now having said this, we are going to make some modifications to the process the MIPS processor you build executes. The modifications are as follows:
  4. You should understand the following code, and place it at address 0 (load the .smokmem file into your memory unit)

    0x00000000: addiu $sp, $0, 1024     # effectively a li $sp, 1024 
    0x00000004: addiu $sp, $sp, -4     # effectively a sub $sp, $sp, 4
    0x00000008: addiu $a0, $0, 10       # effectively a li $a0, 10, set subroutine arg to 10
    0x0000000C: jal fibonacci          # begin your subroutine
    0x00000010: addiu $sp, $sp, 4       # restore stack
    0x00000014: beq $0, $0, -4          # effectively a hold
    0x00000018: ­­­­                        # place your fibonacci program here
    This code sets up the stack pointer, and then makes a procedure call into the fibonacci procedure that you are to write. After returning from fibonacci it removes the stack frame and emulates halting the machine by having a branch instruction jump to itself*.

  5. You can initialize your SMOK-designed processor's memory contents from a smokmem file.  For more about smokemem files, see the "memory" functional component definition here. The smokmem file to use is here.

  6. Your implementation should support the following instructions:
    Arithmetic:
    ADDU, ADDIU, SUBU, SLTI, SLT
    Load/Store:
    LW, SW
    Control:
    JAL, JR, BEQ, BNE

  7. Fibonacci numbers are a rather famous sequence of numbers that go something like this:
    0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, ...
    The basic pattern is F(n) = F(n­1) + F(n­2), with F(0)=0 and F(1)=1. So your function should be like this:
    def fibonacci(n):
    if n==0:
    return 0
    if n<=2:
    return 1
    return fibonacci(n-1)+fibonacci(n-2)
    Note that the function is recursive, so you will need to be careful about how you handle registers. Follow MIPS conventions. Remember to use only the instructions your machine supports. They should be more than enough. Do not worry about improper inputs.
    Please do not be too fancy in how you implement this function. We have to grade it!

  8. It will behoove both of you to work on all parts of this assignment. In other words, you can expect questions on the midterm about designing datapath and control.

  9. Write a short report (one page is plenty) describing:
  10. Turn in your code online, using this form, and turn in your written report in class. Please submit as only one person--there is no need for you and your partner to submit code (or written reports) separately. Just make sure to indicate both partners' information on the turnin, so you will both get a grade. Both written and code parts are due by class on November 13. I suggest you finish the code part early, and leave time to describe it in the written report.

Grading

You will be graded on:
  1. correctness of your machine -- does it run fibonacci correctly?
  2. design of your machine (is it understandable, reasonably fast?)
  3. your written report

Hints