CMSC313, Computer Organization & Assembly Language Programming, Fall 2012

Project 7: Qsort in Assembly

Due: Thursday November 8, 2012, 11:59pm

Objective

The objective of this programming exercise is to practice writing assembly language programs that use the C function call conventions.

Assignment

Your assignment is to write an assembly language program that asks the user to enter a sequence of numbers in stdin then outputs the same sequence sorted in increasing order to stdout. The numbers must be input and output in base 10 and stored as signed 32-bit numbers. You must use the C functions scanf() and printf() for I/O. You must use the qsort() function from the C standard library to sort the data. Using these C functions makes the program much shorter.

The qsort() function has the following function prototype:

void qsort(void *base, size_t nmemb, size_t size, int (*compar)(const void *, const void *)); The first parameter to qsort() is the address of the "array" to be sorted. The second parameter is the number of items in the array. The third parameter specifies the size of each element of the array in bytes (in our case, 32 bits equals 4 bytes). The last parameter is the entry address of a comparison function. You must write this comparison function in assembly language. The comparison function takes two pointers to 32-bit signed integers and returns a negative number, zero or a positive number if the first integer is respectively less than, equal to or greater than the second integer.

A sample run of your program might look like:

linux3% ./a.out
Enter some integers (no more than 100), end with ctrl-D.
? 9
? 12
? 7
? 14
? 3
? 21
? 1
? 
Here are the numbers in sorted order
1
3
7
9
12
14
21
linux3% 

Implementation Notes:

Turning in your program

Use the UNIX submit command on the GL system to turn in your project. When you are done, use the script Unix command to record yourself running your program a few times. You do not have record yourself using gdb for this project.

You should submit 2 files: proj7.asm and typescript. The UNIX command to submit should look like:

submit cs313 proj7 proj7.asm typescript


Last Modified: 22 Jul 2024 11:28:31 EDT by Richard Chang
to Fall 2012 CMSC 313 Homepage