CPSC 330 - Fall 2004 Program 1A Due by 4:00 on Monday, October 4 You may work in teams of two or three on this assignment. Choose _one_ of the team member's programs on which you will base this assignment: 1. Structured walkthrough 2. Revision to bubble to use a subroutine swap (1) The team should perform a structured walkthrough of the code for the selected bubble subroutine. The person who wrote the code should walk through the code, line-by-line, explaining what each line does. The other team members should raise questions regarding any of the following problem areas: (a) correctness (b) readability (c) adherence to the calling convention (d) documentation The team should submit a 1/2 to one page document that includes: * where and when the team met * team members present * team member whose bubble subroutine was selected for this assignment * short rationale as to why this particular version was chosen * results from the walkthrough (a) needed corrections to any errors (b) suggested improvements to readability (c) needed corrections to follow the calling convention (d) suggested improvements to documentation (2) Revise your program to work with a subroutine swap. That is, the bubble subroutine becomes: int bubble( int array[], int count ){ register int i,j,a,b; if( count <= 0 ) return(1); for( i=0; i < count-1; i++ ){ for( j=0; j < count-i-1; j++ ){ if( a[j] > a[j+1] ) swap( &array[j], &array[j+1] ); } } return(0); } and the swap subroutine is: void swap( int *a, *b ){ register int s,t; s = *a; t = *b; *a = t; *b = s; } The parameters should be passed in r1 and r2. Do not change the values of these registers. Your subroutine logic must work for any parameters passed to it even though you will test it and hand it in with one driver. There is no need to return a value in r0. Remember the calling convention: lar r28,swap brl r27,r28 Thus you must save the previous values of r27 and r28 on the stack frame for bubble. Also remember that swap can use any of these registers without saving: r7-r15 - temporary registers (not saved across the call) Thus if any of these hold live values at the point you call swap, you must first save them to the stack, call swap, and then restore them. Also, due to an omission in the description of the calling convention, you should also revise bubble, if necessary, to save and restore (in the prolog and epilog, respectively) any parameter register that you change: r1-r6 - parameters (preserve the values of any not designated as output) You may write swap as a leaf routine, but write it in a modular fashion: - Do not hard code any names from the driver or bubble into swap. - Do not hard code any names from swap into the driver or bubble. Turn in a hard copy of the revised code that uses swap and also implements the corrections and improvements identified in the walkthrough. Also, email a copy to mark@cs.clemson.edu (don't use handin). I may further test your code with a different driver and different swap. (In particular, I may write a pathological swap subroutine that destroys all values in r7-r15.)