Homework 4
|
Modified: |
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.
Translate the algorithm into assembly language using registers to pass the array and number of elements.
int A[] = { 400, 200, 100, 700, 500, 800, 600, 300 }; int B[] = { 5555, 3333, 8888, 0000, 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[], N) { println(); for(int i=0; i<N; i++) { printDec( X[i] ); println(); } } void main() { bubbleSort( A, 8 ); print(A, 8); bubbleSort( B, 10 ); print(B, 10); }
Implement the high-level algorithm as an Assembler language solution.
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 pseudo code comments to the right of assembly instructions.