<< Assembly Unit Home

 ! 
 difficulty rating

Check section A.10 for interesting assembler services

More Hints
Start from familiar high-level code or write algorithm using C-like pseudocode (Show me!)

Objectives
Write a simple 30-50 instruction assembly program with 1-2 nested procedures, 2-3 leaf procedures, and utilizing assembler directives and MIPS pseudo-instructions.

Valid HTML 4.01!

 ! 
 ! 
 ! 
SPIM Exercise 5.1
Load and run this version of procedure sort from your textbook.
  1. Check the pseudoinstruction expansionn
  2. Step through the program
    • Watch registers PC, $ra, and $sp.
    • Watch the stack.

 ! 
 ! 
 ! 
 ! 
SPIM Exercise 5.2
Write a procedure to implement selection sort. Call the procedure "sel_sort". Procedure inputs: list of 32-bit signed integers (pass address), and list size (n).

Use procedures swap and smallest from SPIM Exercises 3.2 and 3.4, respectively. Use the sample list from 3.4 (without the end mark "-1") and the list from 5.1 to test your code.

 ! 
 ! 
 ! 
 ! 
 ! 
SPIM Exercise 5.3 Show me!
Write a procedure to implement insertion sort (see hints to the left). Call the procedure "ins_sort".

  • Input: list of 32-bit signed integers (pass address), and list size (n).
  • Return: address of sorted list.

 ! 
 ! 
 ! 
 ! 
SPIM Exercise 5.4
Write a procedure to implement binary search. Your assembly should be based on this high level code (use the bubble sort procedure from your textbook). Note that you will need a main() to test your work.

  • Input: list of 32-bit signed integer word (pass address), list size (n), and search word (key).
  • Return: address of found word, or -1 if not found.

 ! 
 ! 
 ! 
 ! 
SPIM Exercise 5.5
Write a procedure "median" to calculate the median of an odd-sized list of nonzero 4-byte words. Procedure median should call 2 other procedures: procedure sort from your textbook, and the leaf procedure Mid which you will write. Note that you will need a main() to test your work.

  • Input: list of 32-bit words (pass address), list size (n).
  • Return: the median value if list size odd, or 0 otherwise.
  • Procedure "mid": takes the odd list size and returns the index of the mid-point (for example, if the list size is 11, return 5).

Hint: follow these general steps: test if list size is odd (otherwise exit); sort list; calculate the mid-point index; use mid-point index to loop through list until mid-point element (or to calculate the address of mid-point element directly), use that addr to get the median value. What is the median?