Page 259 - Programming Microcontrollers in C
P. 259

244    Chapter 5  Programming Large 8-Bit Systems

                              IN HOURS
                              TIME
                              ESTIMATED TIME OF ARRIVAL
                              GROUND SPEED


                              The function below was written to show the difference in memory
                          required for the Huffman code and conventional ASCII coding. This
                          program was compiled as a function to be run on the MC68HC11. The
                          function decode given in Listing 5-1 was compiled to MC68HC11 code.
                          The result of these two compilations showed that Listing 5-1 created an
                          object module that was 255 bytes long, and Listing 5-2 created an object
                          module that was 277 bytes long. The Huffman code for even the small
                          message list in this case provided nearly 10% reduction in code size. A
                          larger message list would provide an even greater memory savings
                          because the code required to decode the messages would be allocated
                          over more message characters to be sent out.
                   #include <stdio.h>
                   char M1[]=”ALTITUDE”;
                   char M2[]=”HEADING”;
                   char M3[]=”DISTANCE REMAINING”;
                   char M4[]=”FUEL REMAINING”;
                   char M5[]=”AIR SPEED”;
                   char M6[]=”IN HOURS”;
                   char M7[]=”TIME”;
                   char M8[]=”ESTIMATED TIME OF ARRIVAL”;
                   char M9[]=”GROUND SPEED”;
                   void decode(char *M)
                   {
                       while(*M !=0)
                          putchar(*M++);
                       putchar(‘\n’);
                   }
                              Listing 5-3: Nonencoded Output Function

                          EXERCISES

                          1. How could the tree in Listing 5-1 be altered to reduce its size by 8
                            bytes? What effect would this change have on the routine decode?
                            Would there be a net savings in overall code?
   254   255   256   257   258   259   260   261   262   263   264