* file = example0.asm
* Quick examples of Assembler directives & 6811 code
* Dr. Karl Gugel, 5/2000

* SRAM is at 1040-7FFF Hex on the CME11E9-EVBU 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     $01100	;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     $01180
value1  fcb     27      ;put 27 decimal in mem @ $01180
value2  fcb     30      ;put 30 decimal in mem @ $01181
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.



* Data Transfer Examples
* Program #1 - moving a byte to a new location

        org     $01200  ;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
	rts

* Program #2 - moving a word (two bytes) to a new location
	org	$01300
	ldd	num2	;read in $1234 to D register
        std     results ;store the result in memory locations $110A & $110B
	rts

* Program #3 - load immediate data, transfer to another register & store in mem
	org	$01400
	ldaa	#%10101110	;set A reg to $AE
	tab			;copy it to B reg
	stab	results		;save B reg contents to memory
	rts

* Program #4 - move data using an index register
	org	$01500
	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
	rts


* ARITHMETIC & LOGIC EXAMPLES
* Program #5 - adding (2) byte size numbers & saving the result
        org     $01600
        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             
	rts

* Program #6 - subtracting a byte in memory from an immedate data byte
	org	$01700
	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
	rts

* Program #7 - summing words
	org	$01800
	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
	rts

* Program #8 - bit wise ANDing example
	org	$01900
	ldaa	num1
	nega			;0 - (-1) into A
	anda 	value1		;and $01 with $1b and place into A reg
        staa    sum             
	rts

* 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.  
 
