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

6,2 Passing Parameters                                               157


         *          SUBROUTINE DOTPRD - LOCAL VARIABLES
         TERM:     EQU      0             ; First term of the dot product
        NBYTES:    EQU      2
         *         PARAMETERS
         PARV:     EQU      0             ; Copy of vector V
         PARW:     EQU      2             ; Copy of vector W
         PARDP:    EQU      4             ; Dot product of V and W
         PSIZE:    EQU      6
         *
         DOTPRD:   PULX                   ; Return address into X
                   LEAS     -NBYTES, SP ; Allocation for local variables
                   LDAA     PARV, X
                   LDAB     PARW,X
                   MUL
                   STD      TERM, SP      ; Copy first term into local variable
                   LDAA     PARV+1,X
                   LDAB     PARW+1,X
                   MUL
                   ADDD     TERM,SP       ; Dot product into D
                   STD      PARDP, X      ; Place dot product in out parameter
                   LEAS     NBYTES, SP    ; Deallocate local variables
                   JMP      PSIZE,X

           Figure 625. A Subroutine with Parameters after the Call, which Pulls the Return


         PARV:    EQU    0
         PARW:    EQU    2
         PARDP: EQU      4
         *
                  MOVW V, PARV+L, PCR                  ; Copy of V into parameter list
                 MOVW W,PARW+L,PCR                    ; Copy of W into parameter list
                  BSR    DOTPRD
         L:       DS     6
                 MOVW PARDP+L, PCR, DTPD ; Copy result into DTPD

                    Figure 626. A Subroutine Calling Sequence for Figure 6.25

        rather than a kludge of special methods that are restricted to limited sizes or applications.
        The compiler has less to worry about and is smaller because less code in it is needed to
        handle the different cases. This means that many subroutines that you write for high-
        level languages such as C may require you to pass arguments by the conventions that it
        uses. Moreover, if you want to use a subroutine already written for such a language, it
        will pass arguments that way. It is a good idea to understand thoroughly the stack mode
        of passing parameters.
   175   176   177   178   179   180   181   182   183   184   185