* 68HC11.ASM
* This file is a list of all permutations of 68HC11 instructions
* Written by Kenneth A. Kuhn, March 30, 1994

* Define symbol equates
ADDR_DIR	EQU	$F8	An 8-bit address (upper 8 bits = 0)
ADDR_EXT	EQU	$A45C	A 16-bit address
BYTE_DATA	EQU	$5C	8-bit data
WORD_DATA	EQU	$CFE4	16-bit data
OFFSET		EQU	$7A	8-bit positive offset from X or Y address

********************************************** Load/Store/Transfer Instructions
*	*	*	*	*	*	*	Clear
	CLR	ADDR_EXT	*ADDR_EXT = 0
	CLR	OFFSET,X	*(X + OFFSET) = 0
	CLR	OFFSET,Y	*(Y + OFFSET) = 0
	CLRA			A = 0
	CLRB			B = 0

*	*	*	*	*	*	*	Load registers
	LDAA	#BYTE_DATA	A = BYTE_DATA
	LDAA	ADDR_DIR	A = *ADDR_DIR
	LDAA	ADDR_EXT	A = *ADDR_EXT
	LDAA	OFFSET,X	A = *(X + OFFSET)
	LDAA	OFFSET,Y	A = *(Y + OFFSET)
	LDAB	#BYTE_DATA	B = BYTE_DATA
	LDAB	ADDR_DIR	B = *ADDR_DIR
	LDAB	ADDR_EXT	B = *ADDR_EXT
	LDAB	OFFSET,X	B = *(X + OFFSET)
	LDAB	OFFSET,Y	B = *(Y + OFFSET)
	LDD	#WORD_DATA	D = WORD_DATA
	LDD	ADDR_DIR	D = *ADDR_DIR
	LDD	ADDR_EXT	D = *ADDR_EXT
	LDD	OFFSET,X	D = *(X + OFFSET)
	LDD	OFFSET,Y	D = *(Y + OFFSET)
	LDX	#WORD_DATA	X = WORD_DATA
	LDX	ADDR_DIR	X = *ADDR_DIR
	LDX	ADDR_EXT	X = *ADDR_EXT
	LDX	OFFSET,X	X = *(X + OFFSET)
	LDX	OFFSET,Y	X = *(Y + OFFSET)
	LDY	#WORD_DATA	Y = WORD_DATA
	LDY	ADDR_DIR	Y = *ADDR_DIR
	LDY	ADDR_EXT	Y = *ADDR_EXT
	LDY	OFFSET,X	Y = *(X + OFFSET)
	LDY	OFFSET,Y	Y = *(Y + OFFSET)

*	*	*	*	*	*	*	Store registers
	STAA	ADDR_DIR	*ADDR_DIR = A
	STAA	ADDR_EXT	*ADDR_EXT = A
	STAA	OFFSET,X	*(X + OFFSET) = A
	STAA	OFFSET,Y	*(Y + OFFSET) = A
	STAB	ADDR_DIR	*ADDR_DIR = B
	STAB	ADDR_EXT	*ADDR_EXT = B
	STAB	OFFSET,X	*(X + OFFSET) = B
	STAB	OFFSET,Y	*(Y + OFFSET) = B
	STD	ADDR_DIR	*ADDR_DIR = D
	STD	ADDR_EXT	*ADDR_EXT = D
	STD	OFFSET,X	*(X + OFFSET) = D
	STD	OFFSET,Y	*(Y + OFFSET) = D
	STS	ADDR_DIR	*ADDR_DIR = SP
	STS	ADDR_EXT	*ADDR_EXT = SP
	STS	OFFSET,X	*(X + OFFSET) = SP
	STS	OFFSET,Y	*(Y + OFFSET) = SP
	STX	ADDR_DIR	*ADDR_DIR = X
	STX	ADDR_EXT	*ADDR_EXT = X
	STX	OFFSET,X	*(X + OFFSET) = X
	STX	OFFSET,Y	*(Y + OFFSET) = X
	STY	ADDR_DIR	*ADDR_DIR = Y
	STY	ADDR_EXT	*ADDR_EXT = Y
	STY	OFFSET,X	*(X + OFFSET) = Y
	STY	OFFSET,Y	*(Y + OFFSET) = Y

*	*	*	*	*	*	*	Transfer registers
	TAB			B = A
	TBA			A = B
	TAP			CCR = A
	TPA			A = CCR
	TSX			X = SP
	TSY			Y = SP
	TXS			SP = X
	TYS			SP = Y

*	*	*	*	*	*	*	Exchange registers
	XGDX			Exchange contents of D with X
	XGDY			Exchange contents of D with Y

*	*	*	*	*	*	*	Stack
	PSHA			*SP-- = A
	PSHB			*SP-- = B
	PSHX			*SP-- = X.low, *SP-- = X.high
	PSHY			*SP-- = Y.low, *SP-- = Y.high

	PULA			A = *(++SP)
	PULB			B = *(++SP)
	PULX			X.high = *(++SP), X.low = *(++SP)
	PULY			Y.high = *(++SP), Y.low = *(++SP)


************************************************** Arithmetic/Math Instructions
*	*	*	*	*	*	*	Add
	ABA			A = A + B
	ABX			X = X + B
	ABY			Y = Y + B
	ADCA	#BYTE_DATA	A = A + BYTE_DATA + carry_flag
	ADCA	ADDR_DIR	A = A + *ADDR_DIR + carry_flag
	ADCA	ADDR_EXT	A = A + *ADDR_EXT + carry_flag
	ADCA	OFFSET,X	A = A + *(X + OFFSET) + carry_flag
	ADCA	OFFSET,Y	A = A + *(Y + OFFSET) + carry_flag
	ADCB	#BYTE_DATA	B = B + BYTE_DATA + carry_flag
	ADCB	ADDR_DIR	B = B + *ADDR_DIR + carry_flag
	ADCB	ADDR_EXT	B = B + *ADDR_EXT + carry_flag
	ADCB	OFFSET,X	B = B + *(X + OFFSET) + carry_flag
	ADCB	OFFSET,Y	B = B + *(Y + OFFSET) + carry_flag
	ADDA	#BYTE_DATA	A = A + BYTE_DATA
	ADDA	ADDR_DIR	A = A + *ADDR_DIR
	ADDA	ADDR_EXT	A = A + *ADDR_EXT
	ADDA	OFFSET,X	A = A + *(X + OFFSET)
	ADDA	OFFSET,Y	A = A + *(Y + OFFSET)
	ADDB	#BYTE_DATA	B = B + BYTE_DATA
	ADDB	ADDR_DIR	B = B + *ADDR_DIR
	ADDB	ADDR_EXT	B = B + *ADDR_EXT
	ADDB	OFFSET,X	B = B + *(X + OFFSET)
	ADDB	OFFSET,Y	B = B + *(Y + OFFSET)
	ADDD	#WORD_DATA	D = D + WORD_DATA
	ADDD	ADDR_DIR	D = D + *ADDR_DIR
	ADDD	ADDR_EXT	D = D + *ADDR_EXT
	ADDD	OFFSET,X	D = D + *(X + OFFSET)
	ADDD	OFFSET,Y	D = D + *(Y + OFFSET)

*	*	*	*	*	*	*	Subtract
	SBA			A = A - B
	SBCA	#BYTE_DATA	A = A - BYTE_DATA - carry_flag
	SBCA	ADDR_DIR	A = A - *ADDR_DIR - carry_flag
	SBCA	ADDR_EXT	A = A - *ADDR_EXT - carry_flag
	SBCA	OFFSET,X	A = A - *(X + OFFSET) - carry_flag
	SBCA	OFFSET,Y	A = A - *(Y + OFFSET) - carry_flag
	SBCB	#BYTE_DATA	B = B - BYTE_DATA - carry_flag
	SBCB	ADDR_DIR	B = B - *ADDR_DIR - carry_flag
	SBCB	ADDR_EXT	B = B - *ADDR_EXT - carry_flag
	SBCB	OFFSET,X	B = B - *(X + OFFSET) - carry_flag
	SBCB	OFFSET,Y	B = B - *(Y + OFFSET) - carry_flag
	SUBA	#BYTE_DATA	A = A - BYTE_DATA
	SUBA	ADDR_DIR	A = A - *ADDR_DIR
	SUBA	ADDR_EXT	A = A - *ADDR_EXT
	SUBA	OFFSET,X	A = A - *(X + OFFSET)
	SUBA	OFFSET,Y	A = A - *(Y + OFFSET)
	SUBB	#BYTE_DATA	B = B - BYTE_DATA
	SUBB	ADDR_DIR	B = B - *ADDR_DIR
	SUBB	ADDR_EXT	B = B - *ADDR_EXT
	SUBB	OFFSET,X	B = B - *(X + OFFSET)
	SUBB	OFFSET,Y	B = B - *(Y + OFFSET)
	SUBD	#WORD_DATA	D = D - WORD_DATA
	SUBD	ADDR_DIR	D = D - *ADDR_DIR
	SUBD	ADDR_EXT	D = D - *ADDR_EXT
	SUBD	OFFSET,X	D = D - *(X + OFFSET)
	SUBD	OFFSET,Y	D = D - *(Y + OFFSET)

*	*	*	*	*	*	*	Multiply
	MUL			(unsigned) D = A * B

*	*	*	*	*	*	*	Divide
	FDIV			(unsigned) X = X / D, D = remainder
	IDIV			(unsigned) X = D / X, D = remainder

*	*	*	*	*	*	*	Negate (change sign)
	NEG	ADDR_EXT	*ADDR_EXT = -*ADDR_EXT
	NEG	OFFSET,X	*(X + OFFSET) = -*(X + OFFSET)
	NEG	OFFSET,Y	*(Y + OFFSET) = -*(Y + OFFSET)
	NEGA			A = -A
	NEGB			B = -B

*	*	*	*	*	*	*	Increment
	INC	ADDR_EXT	*ADDR_EXT = *ADDR_EXT + 1
	INC	OFFSET,X	*(X + OFFSET) = *(X + OFFSET) + 1
	INC	OFFSET,Y	*(Y + OFFSET) = *(Y + OFFSET) + 1
	INCA			A = A + 1
	INCB			B = B + 1
	INS			SP = SP + 1
	INX			X = X + 1
	INY			Y = Y + 1

*	*	*	*	*	*	*	Decrement
	DEC	ADDR_EXT	*ADDR_EXT = *ADDR_EXT - 1
	DEC	OFFSET,X	*(X + OFFSET) = *(X + OFFSET) - 1
	DEC	OFFSET,Y	*(Y + OFFSET) = *(Y + OFFSET) - 1
	DECA			A = A - 1
	DECB			B = B - 1
	DES			SP = SP - 1
	DEX			X = X - 1
	DEY			Y = Y - 1

*	*	*	*	*	*	*	Compare
	CBA			CCR flags = result of A - B
	CMPA	#BYTE_DATA	CCR flags = result of A - BYTE_DATA
	CMPA	ADDR_DIR	CCR flags = result of A - *ADDR_DIR
	CMPA	ADDR_EXT	CCR flags = result of A - *ADDR_EXT
	CMPA	OFFSET,X	CCR flags = result of A - *(X + OFFSET)
	CMPA	OFFSET,Y	CCR flags = result of A - *(Y + OFFSET)
	CMPB	#BYTE_DATA	CCR flags = result of B - BYTE_DATA
	CMPB	ADDR_DIR	CCR flags = result of B - *ADDR_DIR
	CMPB	ADDR_EXT	CCR flags = result of B - *ADDR_EXT
	CMPB	OFFSET,X	CCR flags = result of B - *(X + OFFSET)
	CMPB	OFFSET,Y	CCR flags = result of B - *(Y + OFFSET)
	CPD	#WORD_DATA	CCR flags = result of D - WORD_DATA
	CPD	ADDR_DIR	CCR flags = result of D - *ADDR_DIR
	CPD	ADDR_EXT	CCR flags = result of D - *ADDR_EXT
	CPD	OFFSET,X	CCR flags = result of D - *(X + OFFSET)
	CPD	OFFSET,Y	CCR flags = result of D - *(Y + OFFSET)
	CPX	#WORD_DATA	CCR flags = result of X - WORD_DATA
	CPX	ADDR_DIR	CCR flags = result of X - *ADDR_DIR
	CPX	ADDR_EXT	CCR flags = result of X - *ADDR_EXT
	CPX	OFFSET,X	CCR flags = result of X - *(X + OFFSET)
	CPX	OFFSET,Y	CCR flags = result of X - *(Y + OFFSET)
	CPY	#WORD_DATA	CCR flags = result of Y - WORD_DATA
	CPY	ADDR_DIR	CCR flags = result of Y - *ADDR_DIR
	CPY	ADDR_EXT	CCR flags = result of Y - *ADDR_EXT
	CPY	OFFSET,X	CCR flags = result of Y - *(X + OFFSET)
	CPY	OFFSET,Y	CCR flags = result of Y - *(Y + OFFSET)

*	*	*	*	*	*	*	Test
	TST	ADDR_EXT	CCR flags = result of *ADDR_EXT - 0
	TST	OFFSET,X	CCR flags = result of *(X + OFFSET) - 0
	TST	OFFSET,Y	CCR flags = result of *(Y + OFFSET) - 0
	TSTA			CCR flags = result of A - 0
	TSTB			CCR flags = result of B - 0

*	*	*	*	*	*	*	BCD adjust
	DAA			Adjust A for BCD result after ADA, ADD, ADC

********************************************************** Logical Instructions
*	*	*	*	*	*	*	AND
	ANDA	#BYTE_DATA	A = A & BYTE_DATA
	ANDA	ADDR_DIR	A = A & *ADDR_DIR
	ANDA	ADDR_EXT	A = A & *ADDR_EXT
	ANDA	OFFSET,X	A = A & *(X + OFFSET)
	ANDA	OFFSET,Y	A = A & *(Y + OFFSET)
	ANDB	#BYTE_DATA	B = B & BYTE_DATA
	ANDB	ADDR_DIR	B = B & *ADDR_DIR
	ANDB	ADDR_EXT	B = B & *ADDR_EXT
	ANDB	OFFSET,X	B = B & *(X + OFFSET)
	ANDB	OFFSET,Y	B = B & *(Y + OFFSET)

*	*	*	*	*	*	*	OR
	ORAA	#BYTE_DATA	A = A | BYTE_DATA
	ORAA	ADDR_DIR	A = A | *ADDR_DIR
	ORAA	ADDR_EXT	A = A | *ADDR_EXT
	ORAA	OFFSET,X	A = A | *(X + OFFSET)
	ORAA	OFFSET,Y	A = A | *(Y + OFFSET)
	ORAB	#BYTE_DATA	B = B | BYTE_DATA
	ORAB	ADDR_DIR	B = B | *ADDR_DIR
	ORAB	ADDR_EXT	B = B | *ADDR_EXT
	ORAB	OFFSET,X	B = B | *(X + OFFSET)
	ORAB	OFFSET,Y	B = B | *(Y + OFFSET)

*	*	*	*	*	*	*	Exclusive OR
	EORA	#BYTE_DATA	A = A ^ BYTE_DATA
	EORA	ADDR_DIR	A = A ^ *ADDR_DIR
	EORA	ADDR_EXT	A = A ^ *ADDR_EXT
	EORA	OFFSET,X	A = A ^ *(X + OFFSET)
	EORA	OFFSET,Y	A = A ^ *(Y + OFFSET)
	EORB	#BYTE_DATA	B = B ^ BYTE_DATA
	EORB	ADDR_DIR	B = B ^ *ADDR_DIR
	EORB	ADDR_EXT	B = B ^ *ADDR_EXT
	EORB	OFFSET,X	B = B ^ *(X + OFFSET)
	EORB	OFFSET,Y	B = B ^ *(Y + OFFSET)

*	*	*	*	*	*	*	Complement bits
	COM	ADDR_EXT	*ADDR_EXT = ~*ADDR_EXT
	COM	OFFSET,X	*(X + OFFSET) = ~*(X + OFFSET)
	COM	OFFSET,Y	*(Y + OFFSET) = ~*(Y + OFFSET)
	COMA			A = ~A
	COMB			B = ~B

*	*	*	*	*	*	*	Bit test
	BITA	#BYTE_DATA	CCR flags = result of A & BYTE_DATA
	BITA	ADDR_DIR	CCR flags = result of A & *ADDR_DIR
	BITA	ADDR_EXT	CCR flags = result of A & *ADDR_EXT
	BITA	OFFSET,X	CCR flags = result of A & *(X + OFFSET)
	BITA	OFFSET,Y	CCR flags = result of A & *(Y + OFFSET)
	BITB	#BYTE_DATA	CCR flags = result of B & BYTE_DATA
	BITB	ADDR_DIR	CCR flags = result of B & *ADDR_DIR
	BITB	ADDR_EXT	CCR flags = result of B & *ADDR_EXT
	BITB	OFFSET,X	CCR flags = result of B & *(X + OFFSET)
	BITB	OFFSET,Y	CCR flags = result of B & *(Y + OFFSET)

***************************************************** Shift/Rotate Instructions
*  (Note: any bit shifted out goes to carry flag)
*	*	*	*	*	*	Arithmetic shift left
	ASL	ADDR_EXT	*ADDR_EXT = *ADDR_EXT * 2
	ASL	OFFSET,X	*(X + OFFSET) = *(X + OFFSET) * 2
	ASL	OFFSET,Y	*(Y + OFFSET) = *(Y + OFFSET) * 2
	ASLA			A = A * 2
	ASLB			B = B * 2
	ASLD			D = D * 2

*	*	*	*	*	*	Logical shift left
*	LSL	Same as ASL
*	LSLA	Same as ASLA
*	LSLB	Same as ASLB
*	LSLD	Same as ASLD

*	*	*	*	*	*	Arithmetic shift right
	ASR	ADDR_EXT	(signed) *ADDR_EXT = *ADDR_EXT / 2
	ASR	OFFSET,X	(signed) *(X + OFFSET) = *(X + OFFSET) / 2
	ASR	OFFSET,Y	(signed) *(Y + OFFSET) = *(Y + OFFSET) / 2
	ASRA			(signed) A = A / 2
	ASRB			(signed) B = B / 2

*	*	*	*	*	*	Logical shift right
	LSR	ADDR_EXT	(unsigned) *ADDR_EXT = *ADDR_EXT / 2
	LSR	OFFSET,X	(unsigned) *(X + OFFSET) = *(X + OFFSET) / 2
	LSR	OFFSET,Y	(unsigned) *(Y + OFFSET) = *(Y + OFFSET) / 2
	LSRA			(unsigned) A = A / 2
	LSRB			(unsigned) B = B / 2
	LSRD			(unsigned) D = D / 2

*	*	*	*	*	*	Rotate left thru carry
	ROL	ADDR_EXT	*ADDR_EXT = *ADDR_EXT * 2 + carry_flag
	ROL	OFFSET,X	*(X + OFFSET) = *(X + OFFSET) * 2 + carry_flag
	ROL	OFFSET,Y	*(Y + OFFSET) = *(Y + OFFSET) * 2 + carry_flag
	ROLA			A = A * 2 + carry_flag
	ROLB			B = B * 2 + carry_flag

*	*	*	*	*	*	Rotate right thru carry
	ROR	ADDR_EXT	*ADDR_EXT = *ADDR_EXT / 2, b7 = carry_flag
	ROR	OFFSET,X	*(X + OFFSET) = *(X + OFFSET) / 2, b7 = c_flag
	ROR	OFFSET,Y	*(Y + OFFSET) = *(Y + OFFSET) / 2, b7 = c_flag
	RORA			A = A / 2, b7 = carry_flag
	RORB			B = B / 2, b7 = carry_flag

*********************************************************** Branch Instructions
*			Label for branch instructions
REL_ADDR

	BCC	REL_ADDR	Branch if carry_flag clear
	BHS	REL_ADDR	Branch if unsigned compare >=  (BCC)

	BCS	REL_ADDR	Branch if carry_flag set
	BLO	REL_ADDR	Branch if lower

	BEQ	REL_ADDR	Branch if zero flag set
	BNE	REL_ADDR	Branch if zero flag not set

	BGE	REL_ADDR	Branch if signed compare >=
	BGT	REL_ADDR	Branch if signed compare >
	BLE	REL_ADDR	Branch if signed compare <=
	BLT	REL_ADDR	Branch if signed compare <

	BHI	REL_ADDR	Branch if unsigned compare >
	BLS	REL_ADDR	Branch if unsigned compare <=

	BMI	REL_ADDR	Branch if minus
	BPL	REL_ADDR	Branch if positive (or zero)

	BVC	REL_ADDR	Branch if overflow flag is clear
	BVS	REL_ADDR	Branch if overflow flag is set

	BRA	REL_ADDR	Branch always
	BRN			Branch never  (a two-byte NOP)
	NOP			No Operation

*  Test address with BYTE_DATA and branch only if all bits specified by a 1 in 
*  BYTE_DATA are 0 in the tested byte.
	BRCLR	ADDR_DIR, #BYTE_DATA, REL_ADDR
	BRCLR	OFFSET, X, #BYTE_DATA, REL_ADDR
	BRCLR	OFFSET, Y, #BYTE_DATA, REL_ADDR

*  Test address with BYTE_DATA and branch only if all bits specified by a 1 in 
*  BYTE_DATA are 1 in the tested byte.
	BRSET	ADDR_DIR, #BYTE_DATA, REL_ADDR
	BRSET	OFFSET, X, #BYTE_DATA, REL_ADDR
	BRSET	OFFSET, Y, #BYTE_DATA, REL_ADDR

	JMP	ADDR_EXT	Jump to address at *ADDR_EXT
	JMP	OFFSET,X	Jump to address at *(X + OFFSET)
	JMP	OFFSET,Y	Jump to address at *(Y + OFFSET)

******************************************************* Subroutine Instructions
	BSR	REL_ADDR	Save PC on stack and branch to subroutine
*				*SP-- = PC.low
*				*SP-- = PC.high

*  Save PC on stack and jump to subroutine at address given by operand address
*				*SP-- = PC.low
*				*SP-- = PC.high

	JSR	ADDR_DIR	*ADDR_DIR
	JSR	ADDR_EXT	*ADDR_EXT
	JSR	OFFSET,X	*(X + OFFSET)
	JSR	OFFSET,Y	*(Y + OFFSET)

	RTS			Return from subroutine as follows:
*				PC.high = *(++SP)
*				PC.low = *(++SP)

********************************************** Interrupt Processing Instructions
	RTI			Return from interrupt as follows:
*				CCR = *(++SP)
*				B = *(++SP)
*				A = *(++SP)
*				X.high = *(++SP)
*				X.low = *(++SP)
*				Y.high = *(++SP)
*				PC.high = *(++SP)
*				PC.low = *(++SP)

	SWI			Software interrupt as follows:
*				PC = PC + 1
*				*SP-- = PC.low
*				*SP-- = PC.high
*				*SP-- = Y.low
*				*SP-- = Y.high
*				*SP-- = X.low
*				*SP-- = X.high
*				*SP-- = A
*				*SP-- = B
*				*SP-- = CCR
*				I bit of CCR = 1
*				PC = SWI vector

	WAI			Wait for interrupt as follows:
*				PC = PC + 1
*				*SP-- = PC.low
*				*SP-- = PC.high
*				*SP-- = Y.low
*				*SP-- = Y.high
*				*SP-- = X.low
*				*SP-- = X.high
*				*SP-- = A
*				*SP-- = B
*				*SP-- = CCR
*				Wait for an interrupt to occur which has not 
*				been masked.  Then branch to the appropriate 
*				interrupt vector.

*********************************************************** System Instructions

	STOP			Halt system clocks and go to minimum power 
*				standby mode if S bit in CCR is clear.  
*				Otherwise execute a NOP.  Recovery from STOP is 
*				by RESET, XIRQ, or IRQ signal lines.

*	TEST			Only used when processor is in test mode

************************************************* Bit manipulation Instructions

*  Clear all bits at address that are specified by 1's in #BYTE_DATA
	BCLR	ADDR_DIR,#BYTE_DATA
	BCLR	OFFSET,X,#BYTE_DATA
	BCLR	OFFSET,Y,#BYTE_DATA

*  Set all bits at address that are specified by 1's in #BYTE_DATA
	BSET	ADDR_DIR,#BYTE_DATA
	BSET	OFFSET,X,#BYTE_DATA
	BSET	OFFSET,Y,#BYTE_DATA

****************************************** Condition Code Register Instructions

	CLC			Clear carry flag
	CLI			Clear interrupt mask
	CLV			Clear overflow flag
	SEC			Set carry flag
	SEI			Set interrupt mask
	SEV			Set overflow flag
