CSE 378 - Winter 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, February 20

Purpose:

This assignment is where the pieces of the CPU puzzle come together for you: 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. SMOK allows you to design and test architectures at a component abstraction level, i.e., at the register transfer level. Finally this assignment requires you to write a procedure in MIPS assembly (and either hand assemble it or use Spim to assemble it to MIPS machine code*), so that learning the mechanics of procedure stack frames is also a component of this assignment.

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 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, treat register zero as 0* , register 31 as ra, and other 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 a modification to the memory layout of the process the MIPS processor you build executes. This is only a small hack to make things easier for the SMOK tool and yourselves, but it should be easy to see how to modify things to work like the real microprocessor. The hack is 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 halts the machine by having a branch instruction jump to itself*. The smokmem file is here.
  5. Your implementation should support the following instructions:
    Arithmetic:
    ADDU, ADDIU, SUBU, SLTI, SLT
    Load/Store:
    LW, SW
    Control:
    JAL, JR, BEQ, BNE
  6. 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!
  7. 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.
  8. Write a short report (one page is plenty) describing:
  9. 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 2/20. 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. functionality of the fibonacci code on your machine
  2. correctness of your machine
  3. design of your machine (is it understandable, reasonably fast?)
  4. your written report

Hints