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

7,3 From Formulas to Subroutine Calls                                193
































                        Figure 7.11. Stack Movement when Evaluating (8)



                                   PUSH      X
                                   PUSH      K2
                                   PUSH      Y
                                   BSR       FPMUL
                                   BSR        FPADD
                                   PUSH      U                              (10)
                                   BSR        SIN
                                   PUSH      W
                                   BSR       FPADD
                                   BSR       FPDIV
                                   PULL      Z
            How does one write a program segment to evaluate formula or expression (8)? The
        method comes from the work of the Polish logician Jan Lucasiewicz, who investigated
        ways of writing expressions without using parentheses. With his technique, referred to as
        Polish notation, one would write (8) as



        Notice that when reading (11) from left to right, each variable name generates a PUSH in
        (10) and each operation generates a subroutine call. Going between (10) and (11) is easy.
        We soon show a simple algorithm to write a segment for any expression.
            The way to display a formula by parsing it into its basic operations uses a binary
        tree as we will use again in §10.4. Moreover, the technique to write a program segment
   211   212   213   214   215   216   217   218   219   220   221