Homework 4
Conditionals

Modified

Assignment

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, 7777, 1111, 6666, 2222, 4444 };
void bubbleSort( int X[] ) { 
   for(int pass=1; pass < 8; pass++) 
      for(int j=0; j < 8-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[]) {
         for(int i=0; i<8;  i++) {
               printDec( X[i] );
               println();
         }
   }    
			
void main() {
       bubbleSort( A );
       print(A);
       bubbleSort( B );
       print(B);
    }

Turn in

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

Hints

  1. Use the pseudocode program as a guide for program structure.
  2. Pass the beginning offset of the arrays in a register, such as eSi.
  3. Consider using array indexing, such as [eSi+eBx*4] and [eSi+eBx*4+4], in the bubble sort; each entry is 4 bytes.