*
* Tutor1.asm -- Tutorial program 1 for FOX11 board
*               with Wytec Phantom Monitor, (c)2003, EVBplus.com
*		Written By Wayne Chu
*
*     Function:	This program sums up 4 numbers and store the sum
*		at the RAM locations \sum (0 and 1), its average at
*		the RAM locations \average (2 and 3).
*
*     Instructions: 
*		1. Use P command to enter the addresses to be 
*		   monitored, such as p \sum, \average.
*		2. Use B command to set breakpoints at addresses
*		   \next and \finish, such as B \next, B \finish. 
*	*******	For your convenience, we did above 2 steps for you
*
*		3. Enter G \start command to run the program
*		   until it stops at a breakpoint address, then enter
*		   G command to run and until it stops at another
*		   breakpoint address. Repeat the G command until it
*		   stops at \finish.
*		   when it stops at each breakpoint address, you can
*		   watch the values at the locations \sum and \average.
*
* 		You can also verify the result using the F7 math
*		function key at each stop.
*
*
sum:	 equ	$40
average: equ	$50
STACK:   equ    $ff		; stack at top of data ram
*

        org     $F000           ; program code starts here
start:	lds	#STACK
	ldx	#0
clr_more:
	clr	0,x		; clear RAM locations $0-$7F
	inx
	cpx	#$80
	bne	clr_more

	cli			; enable interrupt globely

begin:	ldy	#0
	ldx	#DATA
next:	ldab	0,x		; get data
	beq	done		; done when reaching the end of data
        aby			; add data and store in register y
	sty	sum
	inx			; get next data
	jmp	next

done:	xgdy			; exchange register y with register D
	lsrd			; right shift the 16 bit register D
*				; 0 is shifted into bit 15,
*				; this equals the reister D / 2
	lsrd			; divided by 2 again
	std	average		; store the average 
finish:	jmp	finish
*
DATA:	fcb	$10,$55,$aa,$96,0
*
	org	$FFFE
	fdb	start
	end
*	

