Page 154 - Introduction to Microcontrollers Architecture, Programming, and Interfacing of The Motorola 68HC12
P. 154

5,5 Documentation                                                    131


             It should be noted that, in the relocatable assembler, the INCLUDE directive allows
        breaking up a large program into smaller files that are easier to understand, debug, and
        maintain. You should break up large files into smaller ones, each of which implements a
        conceptually uncluttered collection of operations, and put each such collection into its
        own section. Sections reused in many application programs can be saved in files
        collectively called a library. When a later program needs the same function, it can
        INCLUDE a file from the library that has the function already debugged and assembled.
        Your application program can INCLUDE prefabricated files from a library and parts of
        the program now being written, which are in different files, to break up the larger
        program into smaller sections, each of which is easier to understand, debug, and use.
        While further development of tools to do this are incorporated into object-oriented
        programming, the basic ideas can be incorporated into state-of-the-art assembly-language
        programs as well.
            We continue this section with a list of coding techniques that make your programs
        or subroutines more readable.
             1. Use meaningful labels that are as short as possible.
             2. One should try to write code so that the program flow is progressively forward
             except for loops. This means that one should avoid using unnecessary
             unconditional jumps or branches that break up the forward flow of the program.
             3. Keep program segments short, probably 20 instructions or less. If not
             commented in some way, at least use a line beginning with "*" or ";" to break up
             the code into program segments for the reader.
             4. Including lucid, meaningful comments is the best way to make your program
             clear. Either a comment line or a comment with an instruction is acceptable, but it
             is probably best to use complete lines of comments sparingly. Do not make the
             sophomore mistake of "garbaging up" your program with useless comments, such
             as repeating in the comment what simple instructions do.
             5. The comments at the beginning of the subroutine should be clear enough that
             the body of the subroutine need not be read to understand how to use it. Always
             give a typical calling sequence if parameters are being passed on the stack, after the
             call or in a table. Indicate whether the data themselves are passed (call-by-value) or
             the address of the data is passed (call-by-name). In addition for short subroutines,
             indicate whether registers remain unchanged in a subroutine. Also explain what the
             labels mean if they are used as variables.
                                   CMPY      #1170
                                   BEQ      LI
                                   BMI      L2
                                   CMPB     SI
                                   BEQ      L3
                                   CMPB     S2
                                   BEQ      L4
                                   BRA      Tl
                          Figure 5.8. Example Control Sequence Program
   149   150   151   152   153   154   155   156   157   158   159