Homework 7
|
Modified: |
Homework 4 sorted an array, passing parameters to functions in registers.Homework 6 followed the same algorithm but used pass-by-value and pass-by-reference.
Homework 7 combines C++, Assembler and Macros to implement Homework 6.
An algorithm in C++ is given below to perform a bubble-sort on an array and display the sorted array.
Implement the high-level bubbleSort algorithm as an Assembler language solution.
Use pass-by-reference for array parameter X and pass-by-value for scalar parameter N.
Define and use a macro to interchange the array entries, as is performed in the following:
int temp=X[ j ];
X[ j ]=X[ j+1 ];
X[ j+1 ]=temp;Use the interchange from HW6 as a pattern for the macro code, taking care not to destroy any necessary registers (e.g. use Push/Pop in the macro).
#include <iostream> using namespace std; extern "C" void bubbleSort(int X[], int N); int A[] = { 400, 200, 100, 700, 500, 800, 600, 300 }; int B[] = { 5555, 3333, 8888, 1010, 7777, 1111, 6666, 9999, 2222, 4444 }; extern "C" void print( int X[], int N) { for(int i=0; i<N; i++) cout << X[i] << "\n"; } 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; } print( X, N ); }int main() { bubbleSort( A, 8); bubbleSort( B, 10); return 0; }
Give program listing of solution (e.g. HW7.lst), see Hints on creating a listing file.
Test output using both A and B array values given in the C++.
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.

In Visual Studio:
This will create a file named HW7.lst, containing a listing of the program and macro expansions.