COSC 065 Hardware Systems

Fall 2008

Homework Assignment #7

When Stack Frames Attack

Due: Thursday, Oct 30, 11:59pm CDT.

Submit: Turn in your source files using the turnin command on Morbius. Please name your files "main-q1.S", "main-q2.S", and "readme-q3.txt" for question 3. Failure to follow this simple convention may significantly delay grading of your assignment.

Work may be completed in teams of two. The names of both partners must appear in a comment block at the top of your file for credit to be given. I strongly recommend that you take the time to meet with your partner in person and work together on these projects, rather than work separately and try to integrate at the last minute.

Background

Take time to familiarize yourself with the UNIX environment, using the tutorial here.

Always start your MIPS programming assignments using the MIPS Playground tarball. Download the tarball, and open it in your working directory using the UNIX command "tar xvzf xinu-cosc065.tgz". The file main.S is ready for you to begin programming in MIPS assembly language.

Your work must be compiled on a machine with the proper tools, such as the dual-head Linux boxen in the Systems Lab (CU 310). Consult the professor for advice on connecting remotely if the lab is full or you must work from elsewhere.

In order to assemble your program, use the command "make". In order to run your program, use the command "./mipcon". At any time, you can shutdown the MIPS remote console system by hitting Ctrl-Space, followed by the letter 'q', for 'quit'.

Few rules govern the format of assembly language programs. Make an effort to keep your programs readable and well-documented; sometimes the professor gives partial credit if he can tell what you were trying to do, even if it doesn't quite make it.

Q1 - Grid Printer

Write a MIPS Assembly program that reads an integer number of columns, "n", and then prompts for n more integers representing a column coordinate for each row. Print out an n x n grid representation of the data entered, using zero-based coordinates.

The professor has provided an example program for your reference, runnable on Morbius as ~brylow/cosc065/bin/hw7-grid.

Your program will need to store an arbitrary number of integers before printing out the results. You may either allocate space for a local array on the stack (below the frame pointer of the current function's activation record,) or you may dynamically allocate the space using the malloc() library function.

This type of problem is best implemented using helper functions. (For example, a function printrow(cols, value) that prints out a single row of the grid.) As you write your helper functions, build proper activation records that will allow your functions to strictly abide by the standard calling convention -- this will help a great deal.

Q2 - Towers of Hanoi

The Towers of Hanoi Problem is a classic mathematical puzzle invented by French mathematician Edouard Lucas in 1883. The puzzle was accompanied by a legend of a group of monks solving the puzzle for N = 64; when they finish, according to legend, the world will end.

(This is probably the inspiration for the similarly-themed Arthur C. Clarke science fiction short story, The Nine Billion Names of God.)

Write a MIPS Assembly program that reads an integer, "n", and prints out the proper sequence of moves to solve the Towers of Hanoi puzzle for n disks.

The professor has provided an example program for your reference, runnable on Morbius as ~brylow/cosc065/bin/hw7-hanoi.

Q3 - Activation Records

The Fibonacci number example is compiled into the machine language, and then decompiled using the objdump tool as demonstrated in class, with the results here: fib.s. (Because this code was translated by a compiler, which is itself just a program, the assembly code is not commented and may not be the most effective solution.)

Draw out the activation records that this program has on the stack when at its largest point, assuming fib() was called with a parameter of "4". Label all of the locations in the stack that you can identify, complete with their contents. Because the compiler is not always optimally efficient, there may be unused/unlabeled locations.

Submit your answer electronically as "readme-q3.txt", or you may turn in hardcopy at the beginning of class on Friday if you prefer to work it out on paper.


Back
[Revised 2008 Oct 26 19:35 DWB]