void quicksortC(int a[], int first, int last)
{
int i, pivot, pivotPos, tmp;
if (first < last) {
/* partition; let pivotPos be final position of pivot */
pivot = a[first]; /* use the first element as pivot */
pivotPos = first;
for (i = first+1; i <= last; i++)
if (a[i] < pivot) { /* if you find a smaller element a[i] */
pivotPos++; /* increase pivotPos */
tmp = a[pivotPos]; /* and swap a[i] with a[pivotPos] */
a[pivotPos] = a[i];
a[i] = tmp;
}
/* Now, pivotPos has the correct value, and we swap the pivot there */
tmp = a[pivotPos];
a[pivotPos] = a[first];
a[first] = tmp;
/* now, recursively sort the two halves: */
quicksortC(a, first, pivotPos-1);
quicksortC(a, pivotPos+1, last);
}
}
A driver "callquick.c", the C version "quicksortC.c", and a skeleton
assembly file "quicksortA.s" are provided in
~schar/cs202/hw7/Hint: First, implement and test the partitioning code (comment out the recursive calls in "quicksortC.c"). Then, tackle the recursive calls. Make sure you save and restore any caller-saved registers (eax, ecx, edx) whose values you still need after the call. Also, before restoring any callee-saved registers (ebx, esi, edi) using "popl" instructions at the end of your function, make sure the stack pointer has the correct value as was discussed in class.
Note: Use (at least) 16 "Buffer-4 T.S." from "Simulation Logic.clf". These are "tri-state buffers": if OE (output enable) is active (= 0), the outputs Q are the same as the inputs D. But if OE is not active (= 1), the outputs have state "Z" (i.e., not connected). This allows you to connect multiple outputs, as long as only one of them is enabled. You may want to package the "Buffer-4 T.S." into a smaller subcircuit (with the same pins) so you can fit 16 hex keyboards and 16 buffers close together. Make good use of LogicWork's busses (see chapter 6 of the manual). Your entire ROM should fit into the circuit window in "normal size".
Besides the hex keyboards and the buffers, you will need a few other components to decode the addresses and inputs CS and READ. Feel free to use any of LogicWork's predefined circuits for this. (Hint: search for "decoder".) But if you prefer, you can also define your own subcircuits from simple gates. Once your circuit is completed, test two of your ROMs using an arrangement like this:
Hand in printouts of your top-level test circuit, of your 8x8 ROM implementation, and of any subcircuits you define.
Hand in your paper submission for both parts on Monday. In addition, please submit your assembly program electronically by typing
~schar/bin/submit202in the directory containing your assembly file.