Homework 6
|
Modified: |
Homework 4 sorted an array, passing parameters to functions in registers.Homework 6 follows the same algorithm but uses pass-by-value and pass-by-reference.
A high-level algorithm in pseudocode (that strongly resembles Java or C++) is given below.
The algorithm performs a bubble-sort on an array and displays the sorted array.
int A[] = { 400, 200, 100, 700, 500, 800, 600, 300 }; int B[] = { 5555, 3333, 8888, 1010, 7777, 1111, 6666, 9999, 2222, 4444 };void bubbleSort( int X[], int N) { for(int pass=1; pass < N; pass++) for(int j=0; j < N-pass; j++) if(X[ j ] > X[ j+1 ]) { int temp=X[ j ]; X[ j ]=X[ j+1 ]; X[ j+1 ]=temp; } }void print(int X[], int N) { for(int i=0; i<N; i++) { printDec(count[i]); println(); } } void main() { bubbleSort( A, 8 ); print(A); bubbleSort( B, 10 ); print(B); }
Implement the high-level algorithm as an Assembler language solution.
Use pass-by-reference for array parameter X and pass-by-value for scalar parameter N.
Give program listing of solution.
Test output using both A and B array values given in the pseudocode.
To capture the output window:
For documentation and as helpful reminder of algorithm when debugging assembly code, include pseudocode comments to the right of assembly instructions.
bubbleSort PROC C, X:PTR DWORD, N:DWORD
invoke bubbleSort,
ADDR A, 8