; Exam2study, EE319K Spring 2012
; Instructor: Jonathan W. Valvano
      org  $2000    ; Globals go in RAM
;****PUT YOUR GLOBAL VARIABLES HERE*******

      org  $4000   ; object code goes in ROM
;*************************************************************
;format 8-bit unsigned, first entry is size
Data1 fcb 5,50,100,75,225,50   ; Max1=225,Ave1=100,Cnt1=2
; find the maximum value
; Input parameter: RegY points to array
; Output parameter: RegA maximum value
; Error conditions: none 
Max1 
      rts
; find the average value
; Input parameter: RegY points to array
; Output parameter: RegA average value
; Error conditions: none 
Ave1 
      rts
; Count the number of 50's
; Input parameter: RegY points to array
; Output parameter: RegA number of 50's
; Error conditions: none 
Cnt1 
      rts

;*************************************************************
;format 8-bit signed, first entry is size
Data2 fcb 5,-50,100,-75,-50,50   ; Max2=100,Ave2=-5,Cnt2=3
; find the maximum value
; Input parameter: RegY points to array
; Output parameter: RegA maximum value
; Error conditions: none 
Max2 
      rts
; find the average value
; Input parameter: RegY points to array
; Output parameter: RegA average value
; Error conditions: none 
Ave2 
      rts
; Count the number of values less than 50
; Input parameter: RegY points to array
; Output parameter: RegA values less than 50
; Error conditions: none 
Cnt2 
      rts

;*************************************************************
;format 8-bit unsigned, last entry is termination code=0
Data3 fcb 50,100,75,225,50,0   ; Max3=225,Ave3=100,Cnt3=2
; find the maximum value
; Input parameter: RegY points to array
; Output parameter: RegA maximum value
; Error conditions: none 
Max3 
      rts
; find the average value
; Input parameter: RegY points to array
; Output parameter: RegA average value
; Error conditions: none 
Ave3
      rts
; Count the number of 50's
; Input parameter: RegY points to array
; Output parameter: RegA number of 50's
; Error conditions: none 
Cnt3
      rts

;*************************************************************
;format 8-bit signed, last entry is termination code=0
Data4 fcb -50,100,-75,-50,50,0   ; Max4=100,Ave4=-5,Cnt4=3
; find the maximum value
; Input parameter: RegY points to array
; Output parameter: RegA maximum value
; Error conditions: none 
Max4 
      rts
; find the average value
; Input parameter: RegY points to array
; Output parameter: RegA average value
; Error conditions: none 
Ave4
      rts
; Count the number of values less than 50
; Input parameter: RegY points to array
; Output parameter: RegA values less than 50
; Error conditions: none 
Cnt4
      rts

;*************************************************************
;format 16-bit unsigned, first entry is size
Data5 fdb 5,500,1000,750,2250,500   ; Max5=2250,Ave5=1000,Cnt5=2
; find the maximum value
; Input parameter: RegY points to array
; Output parameter: RegD maximum value
; Error conditions: none 
Max5
      rts
; find the average value
; Input parameter: RegY points to array
; Output parameter: RegD average value
; Error conditions: none 
Ave5 
      rts
; Count the number of 50's
; Input parameter: RegY points to array
; Output parameter: RegD number of 50's
; Error conditions: none 
Cnt5 
      rts

;*************************************************************
;format 16-bit signed, first entry is size
Data6 fdb 5,-500,1000,-750,-500,500   ; Max6=1000,Ave6=-50,Cnt6=3
; find the maximum value
; Input parameter: RegY points to array
; Output parameter: RegD maximum value
; Error conditions: none 
Max6 
      rts
; find the average value
; Input parameter: RegY points to array
; Output parameter: RegD average value
; Error conditions: none 
Ave6 
      rts
; Count the number of values less than 500
; Input parameter: RegY points to array
; Output parameter: RegD values less than 500
; Error conditions: none 
Cnt6 
      rts

;*************************************************************
;format 16-bit unsigned, last entry is termination code=0
Data7 fdb 5000,10000,7500,22500,5000,0   ; Max7=22500,Ave7=10000,Cnt7=2
; find the maximum value
; Input parameter: RegY points to array
; Output parameter: RegD maximum value
; Error conditions: none 
Max7
      rts
; find the average value
; Input parameter: RegY points to array
; Output parameter: RegD average value
; Error conditions: none 
Ave7
      rts
; Count the number of 5000's
; Input parameter: RegY points to array
; Output parameter: RegD number of 5000's
; Error conditions: none 
Cnt7
      rts

;*************************************************************
;format 16-bit signed, last entry is termination code=0
Data8 fdb -5000,10000,-7500,-5000,5000,0   ; Max8=10000,Ave8=-500,Cnt8=3
; find the maximum value
; Input parameter: RegY points to array
; Output parameter: RegD maximum value
; Error conditions: none 
Max8 
      rts
; find the average value
; Input parameter: RegY points to array
; Output parameter: RegD average value
; Error conditions: none 
Ave8
      rts
; Count the number of values less than 5000
; Input parameter: RegY points to array
; Output parameter: RegD values less than 5000
; Error conditions: none 
Cnt8
      rts

Main lds #$4000
;test of array type 1
     ldy #Data1
     jsr Max1  
     ldy #Data1
     jsr Ave1 
     ldy #Data1
     jsr Cnt1 

;test of array type 2
     ldy #Data2
     jsr Max2  
     ldy #Data2
     jsr Ave2
     ldy #Data2
     jsr Cnt2 

;test of array type 3
     ldy #Data3
     jsr Max3  
     ldy #Data3
     jsr Ave3 
     ldy #Data3
     jsr Cnt3

;test of array type 4
     ldy #Data4
     jsr Max4  
     ldy #Data4
     jsr Ave4
     ldy #Data4
     jsr Cnt4 

;test of array type 5
     ldy #Data5
     jsr Max5  
     ldy #Data5
     jsr Ave5 
     ldy #Data5
     jsr Cnt5 

;test of array type 6
     ldy #Data6
     jsr Max6  
     ldy #Data6
     jsr Ave6
     ldy #Data6
     jsr Cnt6 

;test of array type 7
     ldy #Data7
     jsr Max7  
     ldy #Data7
     jsr Ave7 
     ldy #Data7
     jsr Cnt7

;test of array type 8
     ldy #Data8
     jsr Max8  
     ldy #Data8
     jsr Ave8
     ldy #Data8
     jsr Cnt8 
     stop
     lbra Main

     org  $FFFE
     fdb  Main     Start location after reset