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

196                                         Chapter 7 Arithmetic Operations


        The subroutine calls for these consecutive expressions are shown in (12) assuming that
        the 4-byte floating-point numbers c, s, and delta are at addresses C, S, and DELTA,
        respectively.
                                   PUSH      DELTA
                                   PUSH      C
                                   BSR       FPADD
                                   PULL      DELTA
                                   PUSH      S                              (12)
                                   PUSH      DELTA
                                   PUSH      DELTA
                                   BSR       FPMUL
                                   BSR       FPADD
                                   PULL      S
        The example above is easy to work through once you have studied the example for (8).
        Note, however, that a lot of pushing and pulling is done between the variable locations
        and the stack. Seven of the ten macros or subroutines merely move data to or from the
        stack, and three do arithmetic operations. It might be more efficient to use another
        technique for simple problems like this one. The stack method handles more complicated
        situations and offers a completely general technique for evaluating expressions.
            This technique handles formulas of any complexity with ease and accuracy; it can be
        used with any system that uses a stack to hold intermediate results. This approach can be
        used in the 6812 such that the stack pointed to by SP is used to store the intermediate
        results. This approach can be used in the 6812 such that an auxilliary stack (Figure 3.11)
        is used to store these intermediate results. Moreover, a microcontroller such as the 68332
        (§12.4) which has eight data registers analogous to the 6812's two accumulators A and
        B, can use this technique to assign its data registers to store these intermediate results.
        That is, the first item pushed is kept in data register 0, the next in data register 1, and so
        on. In the next section, we find that the stack described in this section is best handled by
        putting its topmost element in registers, like the 68332 does, and to put the remainder of
        the stack described in this section on the hardware stack pointed to by SP.


        7.4 Long Integer Arithmetic


        Multiple-precision arithmetic is very important in microcontrollers because the range of
        integers specified by a 16-bit word, whether signed or unsigned, is too small for many
        applications. Therefore, we will develop 32-bit arithmetic operations in this section. We
        will use the stack discussed in the last section for storage of intermediate results, to
        provide generally useful subroutines. However, due to the use of the register pair Y:D for
        multiplication, we put the top 32-bit element of the stack in register Y (high order 16
        bits) and accumulator D (low order 16 bits); we call this pair of registers "register L."
            It should be clear that pushing and pulling can be done by loading and storing L,
        which is done by loading and storing Y and D. However, to maintain the stack
        mechanism, pushing requires moving L into a long word on the hardware stack. The
        following program segment pushes a long word from location ALPHA.
   214   215   216   217   218   219   220   221   222   223   224