Homework 6
Pass-by-Reference
Pass-by-Value

Modified

Assignment

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);
    }

Turn in

  1. Cover sheet with your name, date, and Homework 6.
  2. 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.

Hints

  1. Use the pseudocode program as a guide for program structure.
  2. For function definition and calling, consider using:

    bubbleSort     PROC C, X:PTR DWORD, N:DWORD

    invoke           bubbleSort, ADDR A, 8
     

  3. Move the beginning offset of the arrays in a register, such as eSi.
  4. Consider using array indexing, such as [eSi+eBx*4] and [eSi+eBx*4+4], in the bubble sort and print procedures; each entry is 4 bytes.