CS301 – Fall 2003

Prof. Hartman

Homework #5

Due Wednesday, October 29th by 4:45 pm

 

As we are will eventually find out in class lectures, shorter (smaller) code is almost always faster. In this assignment your goal is to generate the shortest code possible to solve the problem. Roughly one third of your homework grade will be dependent on how short your code is.

 

Write an assembly language function matching the following C prototype:

     void sort(int *array, unsigned int numelements);

Your routine will take two parameters, a pointer to an array of (signed) integers (ie. doublewords), and an (unsigned) integer telling you how many elements are in the array. You need to sort the array, in place. You may not make any calls from your routine.

 

Turn in the output generated when calling your function from the code below. Also turn in the listing file for your program.

 

// Here is the code to use to test your program

 

#include <stdio.h>

 

void sort(int *array, unsigned int numelements);

 

int main()

{

int i;

int a[50]= {-903, -469,   -6, 700, -505, -327, -102,  806, -805,  111,

            -820, -440, -467, 980, -146, -269,  181, -311, -103,  142,

             832,  922,  261, 265,  780, -375,    3,  548, -648,  942,

            -159,  357, -298, 931,   21,  624, -521,  768,  758,  619,

              -6,  -24,  450,  26,  704,  953,  303, -770, -266, -909};

 

sort(a,50);

for(i=1;i<=50;++i)

   {

   printf("%6d",a[i-1]);

   if(i%10==0) printf(“\n”);

   }

return 0;

}