* file = example2.asm
* Quick examples of Assembler directives & 6812 code
* Dr. Karl Gugel, 12/2001

* Sim12 is based on the M68HC12AEVB. It assumes the following memory map:
* 16K External RAM at $4000-$7FFF
* 32K External ROM at $8000-$FFFF
* Internal RAM at $800-$BFF
* Internal EEPROM at $1000-$1FFF
* Note: You can load in programs anywhere in the above mentioned areas but should
*       only write to RAM (i.e. assume ROM and EEPROM are read only).  


* This program looks for a specific character in a given string and then returns
* how many times it was used in the string.  All strings must be terminated with
* a zero byte which denotes end of string. 

STRING_ADDR	equ	$F000	;where the test string is found
PROGRAM_ADDR	equ	$8000	;where program will be placed
CHARACTER	equ	'o'	;test character to look for in the string
USEAGE_ADDR	equ	$800	;where the final useage count is stored 

* Test String
		
		org	STRING_ADDR
		dc.b	'If you are going to pass, you gotta love this class.'
EOS_CODE	dc.b	0	;end of string code

* Main Program

		org	PROGRAM_ADDR
		ldx	#STRING_ADDR	;test string address
		ldab	#CHARACTER	;character to count in string
		ldaa	#0		;zero character count
		staa	USEAGE_ADDR

main1		ldaa	0,x		;get character
		cba			;check if it is our test char
		bne	skip1		;no, then skip counting it
		inc	USEAGE_ADDR

skip1		inx			;inc string pointer
		cmpa	EOS_CODE	;check if end of string code
		bne	main1
end1		bra	end1