;******************************************************************+
;* Group:                                                         *
;* Group Members and andrew id:                                   *
;* Lab/Prelab:                                                    *
;******************************************************************+




;******************************************************************+
;* This stationery serves as the framework for a                   *
;* user application (single file, absolute assembly application    *
;* for 18-348)                                                     *
;******************************************************************+

; export symbols
            XDEF Entry            ; export 'Entry' symbol
            ABSENTRY Entry        ; for absolute assembly: mark this 
                                  ; as application entry point


; include derivative specific macros
            INCLUDE 'mc9s12c128.inc'

; variable/data section
            INCLUDE 'RAMLocation.inc'
            
;****************************************************
; ADD GLOBAL VARIABLES HERE
;****************************************************

ROMStart    EQU  $4000  ; absolute address to place my code/constant data

; code section
            ORG   ROMStart
Entry:
            INCLUDE 'StackInfo.inc'

            CLI                   ; enable interrupts

;*****************************************************
; ADD CODE HERE
;*****************************************************
      ;TODO write code to push arguments
      ;use the values:
      ; m = $11
      ; n = $20
      ; p = $1010
      ; q = $05FF

      ;TODO write code to create return value

      ;TODO call customFunction

      ;TODO store the return value in the X register

      ;TODO clean up return value and arguments from the stack

      
loopForever:
      BRA loopForever

;function implementation:
;unsigned int customFunction(unsigned char m,
;                             unsigned char n,
;                             unsigned int p,
;                             unsigned int q)
customFunction:
      ;TODO create local variables (if needed)

      ;TODO write code to perform computation
            
      ;TODO write computation result into return value
      ;computations for each group are:
      ;group 1:  (3*m*n) + p + q
      ;group 2:  (m + n) - (2 * (p+q))
      ;group 3:  (m - n) + (q + (2*p))
      ;group 4:  (5*m + n) + q + (3*p)
      ;group 5:  (2*m*n) - p - q
      ;group 6:  (m * n) - (2 * p) + q
      ;group 7:  (m - 4*n) + 2*q + p
      ;group 8:  (3 * (m - n)) + q + 3*p
      ;group 9:  (4*m + 2*n) - q - p
      
      
      ;TODO destroy any local variables
      
      ;TODO return from function


;*****************************************************
;     DO NOT MODIFY OR ADD ANYTHING AFTER THIS POINT!
;*****************************************************

;**************************************************************
;*                 Interrupt Vectors                          *
;**************************************************************
            ORG   $FFFE
            DC.W  Entry           ; Reset Vector
