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

162                                Chapter 6 Assembly Language Subroutines


           *        SUBROUTINE DOTPRD
           *        PARAMETERS
           *
           PARV:    EQU   0           ; Copy of vector V
           PARW:    EQU 2             ; Copy of vector W
           PARDP: EQU 4               ; Dot product of V and W
           *
           *        LOCAL VARIABLES
           *
           TERM:    EQU   0
           MBYTES: EQU    2
           DOTPRD: LEAS -NBYTES, SP ; Allocation for local variables
                   LDAA PARV,X
                    LDAB PARW,X
                   MUL                ; First term of DP into D
                    STD   TERM, SP    ; Store in local variable
                    LDAA PARV+1,X
                    LDAB PARW+1,X
                   MUL                ; Second term into D
                    ADDD TERM,SP
                    STD   PARDP, X    ; Place dot product
                    LEAS NBYTES, SP ; Deallocate local variables
                    RTS
                                     a. The subroutine

                  LDX fTABLE
                  MOVW V, PARV, X      ; Place copy of V into parameter
                  MOVW W, PARW, X      ; Place copy of W into parameter
                  BSR   DOTPRD         ; Call Subroutine
                  MOVW PARDP, X, DTPD ; Copy result into global variable
                                    b. Calling sequence

                  Figure 633. Calling Sequence for Passing Arguments in a Table


        6.3 Passing Arguments by Value, Reference, and Name

        Computer science students, as opposed to electrical engineering students, study the
        passing of parameters in high-level language subroutines on a different level than that
        used in the preceding section. We include this section to explain that level to you. On
        the one hand, this level is very important if, say, you are writing or using a subroutine
        that is used by a high-level language program and that subroutine has to conform to the
        properties discussed below. On the other hand, the differentiation between some of the
        characteristics discussed below is rather blurry in assembly language programs.
   180   181   182   183   184   185   186   187   188   189   190