<< Assembly Unit Home

 ! 
 difficulty rating

Check section A.10 for interesting assembler services

More Hints
    Write an algorithm
    Analyze cases
    Break down code to smaller, single purpose procedures
Hide 5.2 hint

Objectives
  • Distinguish real and pseudo instructions.
  • 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. Step through the program and note registers PC, $ra, and $sp. Watch the stack. Check the pseudoinstruction expansions against the code in your textbook.

 ! 
 ! 
 ! 
 ! 
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.

Algorithm sel_sort
Input: addr_list (addr of list to be sorted), n (list length)
Output: addr_list
------------------------------
begin
addr_sublist = addr_list - 4;
m = n;
while ( m > 1 )
begin
addr_sublist = addr_sublist + 4;
addr_smallest = smallest (addr_sublist, m);
swap (addr_sublist, addr_smallest);
m = m - 1;
end
return list_addr
end

Some analysis to help understand the algorithm.

Case n m Iterations
List empty 0 0 0
Single item 1 1 0
List size > 1 2,3,4,... 2,3,4,... 1,2,3,...