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

4.2 Assembler Directives                                             95


            The actual value of the container TABLE will depend on where it is placed in the
        program. Note that, in contrast to the DS directive, this directive initializes or assigns
        values to the container (the address) as well as allocating room for its contents (the word
        at that address). Beware, however, that the contents are given this value only when the
        program is loaded into memory. If the program is reran without being loaded again, the
        value of the contents is what was left there as a result of running the program the last
        time. When rerunning the program, you should check these values and possibly rewrite
        them before you assume they are the contents specified by the program.
            The DC. W (define constant word) directive does exactly the same thing as DC. B in
        (4) except that now two bytes are used for each value in the operand field, where, as
        usual, the high byte is first. For example, the directive
                              TABLE      DC.W 14,17,19,30                    (5)
        puts the values in memory as shown.


















            The DC. L directive allocates and initializes a 32-bit memory block for each item in
        the directive's operand list. Its mechanism is essentially like that for DC .W in (5).
            The DC. B directive can have a sequence of ASCII characters in the operand field.
        (See Table 4.1 for a table of ASCII characters and their representations.) The ASCII
        codes for the characters are now put in the successive memory locations. The most
        convenient form is
                              LIST DC.B     "ABC"

        where quotes enclose all the ASCII characters to be stored, namely, A, B, and C. Single
        quotes can be used instead of these quotes, especially where a character is a quote.
            The define constant block DCB. B directive has a number n and a value v in the
        operand field; n copies of v are now put in the successive memory locations. Suffixes
        .B, .W, and .L can be used in an obvious way, and . B is the default.
            To see how these directives might be used, suppose that we wanted to store a table
        of squares for the numbers between 0 and 15. The program, whose assembler listing is
        shown in Figure 4.4, uses this table to square the number N, returning it as NSQ. With
                                          2
        the given data structure, the location of N  equals the location TABLE plus N. Thus if X
        contains the location TABLE and B contains the value of N, the effective address in the
                                           2
        instruction LDAA B, X is the location of N .
   113   114   115   116   117   118   119   120   121   122   123