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

158                                Chapter 6 Assembly Language Subroutines


         *        SUBROUTINE DOTPRD
         *        LOCAL VARIABLES
         TERM:    EQU    0            ; First term of the dot product
         MBYTES: 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
         *
         DOTPRD: LDX 0, SP            ; Return address into X
                  LEAS   -NBYTES, SP ; Allocation for local variables
                  LDAA PARV+2,X
                  LDAB PARW+2,X
                  MUL
                  STD    TERM, SP     ; Copy first terra into local variable
                  LDAA PARV+1+2,X
                  LDAB PARW+1+2,X
                  MUL
                  ADDD   TERM,SP     ; Dot product into D
                  STD    PARDP+2, X ; Place dot product in out parameter
                  LEAS   NBYTES, SP ; Deallocate local variables
                  RTS

              Figure 6.27. A Subroutine with Parameters after the Call, which Uses RTS


           entry: MOVW V, PARV+L, PCR       ; Copy of V into parameter list
                   MOW W,PARW+L,PCR         ; Copy of W into parameter list
                   BSR DOTPRD
                   BRA LI
           *
           L:      DS 6
           *
           L1:     MOVW PARDP+L, PCR, DTPD ; Copy parameter list into DTPD

             Figure 6.28. A Subroutine Call with Parameters after the Call for Figure 6.27


            We now consider another common method of passing arguments in which they are
        put after the BSR or equivalent instruction. This way, they look rather like addresses that
        are put in the instruction just after the op code. Two variations of this technique are
        discussed below.
   176   177   178   179   180   181   182   183   184   185   186