* Parameters pointers on stack

	ORG		 $0B00
LOCAT1:	DC.B	$37	 ;Define location of data
	ORG		 $0B06
LOCAT2:	DC.B	$A3	 ;	and some default data

**** Main routine
	ORG	$0900	;Start program at $0900
START:	LDS	#$900	;initialize stack pointer
	LDX	#LOCAT2	;Put location of 2nd data
	PSHX		;  onto stack
	LDX	#LOCAT1	;Put location of 1st data
	PSHX		;  onto stack
*	JSR	AVGA	;Call subroutine AVGA
	JSR	AVGB	;Call subroutine AVGB
HERE:	BRA	HERE	;Stay Here(endless loop)
 
*********************************************************
**** Subroutine: AVG
* Get average of numbers pointed to by addresses
*   on the stack
* Output in accumulator A
* A,B,X,Y affected; stack modified
	ORG	$A00
AVGA	PULX		;Save return address
	PULY		;Get address of 1st data
	LDAA	0,Y	;Put first data in A
	PULY		;Get address of 2nd data
	ADDA	0,Y	;A=A + 2nd data
	ASRA		;Divide by 2
	PSHX		;Fix stack for return add.
	RTS
*******************************************************
* Get average of numbers pointed to by addresses
*   on stack
* Output in accumulator A
* A,B,X,Y affected; stack unmodified
* Stack unmodified AND THUS HAS LEFT OVER INFO
*     Every call increases the size of the data on the stack
*********************************************************
	ORG	$A80
AVGB:	TSX		;IX = SP & IX points to the stack
	LDY	2,X	;Get address of 1st data
	LDAA	0,Y	;Put first data in A
	LDY	4,X	;Get address of 1st data
	ADDA	0,Y	;A=A + 2nd data
	ASRA		;Divide by 2
	RTS

