Anda di halaman 1dari 2

Useful instructions

Instruction
LDAA

Examples
LDAA 10
; load an 8-bit block of data from memory location 10 in accuma
LDAA #10; load the value 10 in accuma
LDAA MEM
; load an 8-bit block of data from memory location MEM in accuma
LDAA #MEM
; ERROR! load the 16-bit address of MEM into accuma
LDAA 0,X
; load an 8-bit block of data from memory location [X + 0] in accuma
LDAA 0,Y
; load an 8-bit block of data from memory location [Y+ 0] in accuma
Other instruction wit same format:
LDAB
STAA
STAB
CMPA (compare a to memory)
CMPB (compare b to memory)
COMA
; invert the bits
COMB
SUBA
;result is stored in a
SUBB
;result is stored in b
ADDA
; result is stored in a
ADDB
; result is stored in b
ADDD
;result is stored in b
SBA
; subtract b from a result is stored in a
CBA
; compare a with a
MUL

MUL

; multiply accuma*accumb and store to accumd

LDD

LDAA 10
; load an 16-bit block of data from memory location 10 in accumD
LDAA #10; load the value 10 in accumD
LDAA MEM
; load an 16-bit block of data from memory location MEM in accumaD
LDAA #MEM
; load the 16-bit address of MEM into accumD
LDAA 0,X
; load an 16-bit block of data from memory location [X + 0] in accumD
LDAA 0,Y
; load an 16-bit block of data from memory location [Y+ 0] in accumD
Other instructions with same format:
STD
STX
STY
LDX
LDY
CPY (compare Y to memory)
CPX (computer X to memory)
TAB
TBA
CLRA
CLRB

TAB
TBA
CLRA
CLRB

CLR

;transfer A to B (copy the contents of accuma to accumb)


;transfer B to A (copy the contents of accumb to accuma)
;clear accuma (set to zero)
;clear accumb (set to zero)

CLR MEM1
CLR 10
CLR 0,X
CLR 0,Y
CLR #10
CLR #MEM
Other instructions with the same format:
INC
DEC

;clear the contents of MEM1


;clear the contents of memory location 10
;clear the contents of memory location 0+X
;clear the contents of memory location 0+Y
;ERROR (it doesnt mean anything to clear a number)
;ERROR (it doesnt mean anything to clear an address)

INCA
INCB
INX
INY

;Accuma = Accuma +1
;Accumb= Accumb+1
;Accumx=Accumx+1
;Accumy=Accumy+1

INCA
INCB
INX
INY

Other instructions with the same format


DECA
DECB
DEX
DEY
BHI

;this branches when the result of the last compare operation returned that the first operand was larger. Further, ;this assumes that the numbers
being compared were less than zero. ONLY use this (versus BGT) if you want
;to compare POSITIVE numbers only. This will not handle 2s complement numbers.
LDAA
#10
CMPA
#9
BHI
LABEL
This code will ALWAYS branch to LABEL
LDAA
#100
CMPA
#-128
BHI
LABEL

Even though 100 is greater than -128, this will never branch. The reason is that -128 is represented as positive 128 if we are interpreting the
numbers as unsigned.
Other instructions with the same format:
BLO
BGT
BLT
BEQ
JMP
BRA

JMP LABEL ; this functions the same as a BRA (branch always)

NOTE: never use BRA. The reason is that BRA has a strict limit on the distance that it can branch (and it isnt that far). Thus, if you ever want to branch from one part
of the program to another part that is far away, it is a much better idea to use a jmp than a bra. That being said, if you need to make a comparison operation, then branch
to a label close by and jump from there.
JSR
RTS
RTI
XGDX
XGDY
TSX
TSY
TXS

; This jumps to a service routine and stores the address of the JSR instruction to the stack
; This pops off a 16-bit value (the return address) from the system stack and jumps to that location
; This is to return from an interrupt
; This swaps the contents of D and X
; This swaps the contents of D and Y
; This transfers the stack pointer to X
; This transfers the stack pointer to Y
; This transfer X to the stack pointer (not that this instruction should NEVER be used!!)

IDIV
FDIV

; integer divide D/X result in D, remainder in X


; floating point divide D/X result in D, remainder in X

A tip:
You will find that you will be using memory locations much like local variables (or registers) within HC11. As such, you many find that you are creating a great number
of temporary memory locations that will end up as wasted memory most of the time.
To solve this problem, we can dynamically allocate memory for each of our functions.
Example: instead of allocating two temporary variables TEMP1 and TEMP2, we can do the following.

JSR

MYFUNC

MYFUNC:
pshx
pshy
psha
pshb
ldx
pshx
pshx
tsx

/* Save all of the registers */

#0
/* CREATE TEMP1 on STACK */
/* CREATE TEMP2 on STACK */
//copy the stack pointer to X

//some code is written here


//lets say that we want to perform the following operation TEMP1=TEMP2+1
//we would do the following:
ldy
XGDY
ADDD
XGDY
Sty

0,X
#1

;remember NOT to overwrite X


;we can only perform ADD and SUB on accuma and accumb
;increment d by 1
;put the incremented value back in Y

0,X

//some code here


//now when we return from the function we do the following to clean up the stack and return
pulx
;take everything off of the stack
pulx
pulb
pula
puly
pulx
rts
;Note: there is no reason to need the use of accumulator Y in the previous example. It was used to demonstrate
;the usefulness of XGDX/XGDY instructions

Anda mungkin juga menyukai