Lab 5, Part II: The CC5X Compiler

 

This  portion of the assignment involves the use of compiler software written by B. Knudsen (http://www.bknd.com/). The software runs under DOS is involves a simple command line statement shown below. As stated in lecture the goal of this part of the assignment is to create assembly-level versions of the provided insertion sort code, one generated by the compiler and the other hand-written by you. Each version is then assembled using MPASM and simulated to determine performance. Step-by-step details on how to accomplish these tasks are provided below. Note that the values to be sorted in the C program and fixed by the program to simplify the experiment. These instructions have been created by one of the TAs (Damian Nowak). Please feel free to contact him at dnowak@student.umass.edu with any questions.

 

1.) First download the insertion algorithm C code.  Click here for the source. 

      A description of insertion sort can be found here:  http://www.aihorizon.com/essays/basiccs/lists/sorting/insertion.htm

      There’s also one in the data structures book from ECE 242.

     -Some comments about the code in case you wanted to know:

·       #pragma chip PIC16F877  defines the PIC that is targeted.

·       All operations are carried out in the main routine

·       While another function could be called to perform an operation no data can be passed to the function, i.e.

         It would have to defined be:

         void func(void)

·       Only one indirect reference can occur per line:

k = array[j-1];

array[j] = k;

     This could not be simplified to one line.

 

2.) Download the CC5X compiler:  cc5xfree.zip

      Unzip into a directory of your choice.  Put the insert.c file into the directory.

      To generate the assembly code type:  cc5x –a insert.c 

      If there are any errors they will be reported (there shouldn’t be).

 

3.) Compile the source code using MPLAB.

 

4.) Open the File Register Memory by clicking the icon.  You will use this window to determine the correct operation of the code.

 

5.) As you step through the program you will notice the data array is being created in memory locations 002006 – 00200F. 

     Data values 0A – 01 will fill these locations.  IMAGE

 

6.) If you let the program finish running you will notice these same memory locations have now been sorted and the

     data is ordered 01 – 0A. IMAGE

 

7.) To determine how many cycles your program takes to finish, put a breakpoint at the end at of the program, in this example the program is finished at line 138, the SLEEP statement. Then go to the Window menu and select the Stopwatch option. This will tell you the number of cycles and amount of time the program will take to complete. You will use this to compare the performance of your assembly code to the automatically generated assembly.

 

8.) Your job is to write your own version of the insertion sort algorithm in PIC assembly and compare the performance to the automatically generated code. Make sure to generate your array in the same manner as in the example, in reverse order, for consistency.