* file = example0.asm
* Quick examples of Assembler directives & 6811 code
* Karl Gugel and Eric Schwartz, 17 Aug 2001

* SRAM is at 1040-7FFF Hex on an memory-expanded 68HC11 board.

* DATA ALLOCATION SECTION - variables & constants
* Data can go before or after your program but should
* not in the middle of a program for clarity reasons.
	org     $1100	;these are all assembler directives
num1	fcb     $FF  	;single byte placed in memory starting at $1100     
num2	fdb     $1234	;double byte placed in memory
char	fcc     'E' 	;ASCII characters (one byte each)
	fcc     'E'
	fcc     'L'
	fcc     '3'
	fcc     '7'
	fcc     '0'
	fcc     '1'
results rmb     3	;reserved space for future use

	org     $1180
value1	fcb     27	;put 27 decimal in mem @ $1180
value2	fcb     30	;put 30 decimal in mem @ $1181
sum	rmb     1	;reserve a byte for a future sum

* Special Note:  Assembler directives are used to place data
*                and variables into memory.  They are not 6811
*                instructions and thus are not executed at run
*                time.  When this program is loaded into memory,
*                the data (created above by the assembler) is also
*                copied down into memory.

* The below examples are "program fragments."  If an RTS instruction
* is added to the end of each fragment (and a label is added at the 
* start), these examples would then be called "subroutines."

* Data Transfer Examples
* Program #1 - moving a byte to a new location

	org     $1200	;code will be placed at $1200 in memory
	ldaa    num1	;this reads FF into Accum. A
	staa    results	;FF is stored at memory location $110A

* Program #2 - moving a word (two bytes) to a new location
	org	$1300
	ldd	num2	;read in $1234 to D register
	std     results	;store the result in memory locations $110A & $110B

* Program #3 - load immediate data, transfer to another register & store in mem
	org	$1400
	ldaa	#%10101110	;set A reg to $AE
	tab			;copy it to B reg
	stab	results		;save B reg contents to memory

* Program #4 - move data using an index register
	org	$1500
	ldx	#num1		;load the address that corresponds to num1
	ldy	#results	;load the addr that corresponds to results
	ldaa	0,x		;loads A reg with $FF
	staa    2,y	     ;stores $FF at mem location $110c

* ARITHMETIC & LOGIC EXAMPLES
* Program #5 - adding (2) byte size numbers & saving the result
	org     $1600
	ldaa    value1		;27 decimal into reg A   	
	ldab	value2		;30 decimal into reg B
	aba			;sums A & B and places result back into A
	staa    sum

* Program #6 - subtracting a byte in memory from an immedate data byte
	org	$1700
	ldab	#$20		;place 32 decimal in B reg
	subb	value2		;subtract 30 decimal from 30
	ldx     #$1040	  ;load X reg with $1040
	stab    0,x	     ;store 02 result at $1040 in memory

* Program #7 - summing words
	org	$1800
	ldd	num2		;D reg contains $1234
	addd	num2		;adds $1234 + $1234 = $2468
	ldy	#num2		;load Y with addr of num2
	std     9,y	     ;store $2468 at addr $1101 + 9 = $110A

* Program #8 - bit wise ANDing example
	org	$1900
	ldaa	num1
	nega			;0 - (-1) into A
	anda	value1		;and $01 with $1b and place into A reg
	staa	sum	     

* Instructions you are responsible for understanding (but don't have to 
* memorize): TAB, TBA, TAP, TPA, TSX, TXS, TSY, TYS, XGDX, XGDY, LDAA,
* LDAB, STAA, STAB, LDw where w = X,D,Y or S, STw where w = X,D,Y or S,
* ABA, ABX, ABY, ADDA, ADDB, ADDD, SBA, SUBA, SUBB, SUBD, INC, INCz where
* z = A,B,S,X or Y, ANDA, ANDB, ASL, ASLD, ASR, CLR, CLRA, CLRB, DEC,
* DECA, DECB, DES, DEX, DEY, EORA, EORB, LSL, LSLD, LSR, LSRD, NEG, NEGA,
* NEGB, ORAA, ORAB, ROL, and ROR.  
 