* Parameters on stack

**** Main routine
	ORG	$0900	;Start program at $0900
START:	LDS	#$900	;initialize stack pointer
	LDAA	#$37	;Load data onto stack
	PSHA
	LDAA	#$A3
	PSHA
	JSR	 AVGA	;Call subroutine AVGA
*	JSR	 AVGB	;Call subroutine AVGB
HERE:	BRA	 HERE	;Stay Here(endless loop)
 
*********************************************************
**** Subroutine: AVG
* Get average of inputs on stack
* Output in accumulator A
* A,B,X affected
* Stack modified
	ORG	 $A00
AVGA	PULX		;Save return address
	PULA		;Get the second data item
	PULB
	ABA		;A=A+B
	ASRA		;Divide by 2
	PSHX		;Fix stack for return
*			;  address
	RTS
*******************************************************
* Get the average of the inputs on the stack
* Output in accumulator A
* A,X affected
* 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
	LDAA	2,X	;A = 1st parameter
	ADDA	3,X	;A = A + 2nd parameter
	ASRA		;Divide by 2
	RTS

