Super NES Programming/65c816 reference

< Super NES Programming

Internal Registers

RegisterDescription
AThe accumulator. This is the math register. It stores one of two operands or the result of most arithmetic and logical operations.
X, YThe index registers. These can be used to reference memory, to pass data to memory, or as counters for loops.
SThe stack pointer, points to the next available(unused) location on the stack.
DBRData bank register, holds the default bank for memory transfers.
DDirect page register, used for direct page addressing modes.
PBRProgram Bank, holds the bank address of all instruction fetches.
PProcessor Status, holds various important flags, see below.
Flags stored in P register
MnemonicValueBinary Value Description
N#$8010000000Negative Condition codes used for branch instructions.
V#$4001000000Overflow
Z#$0200000010Zero
C#$0100000001Carry
D#$0800001000Decimal
I#$0400000100IRQ disable
X#$1000010000Index register size (native mode only)

(0 = 16-bit, 1 = 8-bit)

M#$2000100000Accumulator register size (native mode only)

(0 = 16-bit, 1 = 8-bit)

Enot in P6502 emulation mode
B#$1000010000Break (emulation mode only)

Instructions

Arithmetic and Logical Instructions

InstructionDescriptionArgumentsFlags set
ADCAdd A with something and carry bit. Result is put in A.Immediate value or addressn,v,z,c Arithmetic instructions
SBCSubtract something and the carry bit.n,v,z,c
ANDAND A with memory, storing result in A.Immediate value or addressn,z Logical instructions
EORExclusive orn,z
ORAOR A with memory, storing result in A.Immediate value or addressn,z
TSBTest and set bitsz
TRBTest and reset bitsz
ASLArithmetic shift left A or address c Shift instructions
LSRLogical shift right A or address c
ROLRotate left A or address c
RORRotate right A or address c
BITtest bits, settingimmediate value or addressn,v,z (only z if in immediate mode) Test instructions
CMPCompare accumulator with memoryn,z,c
CPXCompare register X with memoryn,z,c
CPYCompare register Y with memoryn,z,c
DEADecrement Accumulatorn,z
DECDecrement, see INCn,z
DEXDecrement X registern,z
DEYDecrement Y registern,z
INAIncrement Accumulatorn,z
INCIncrement, see DECn,z
INXIncrement X registern,z
INYIncrement Y registern,z
NOPNo operationnone
XBAExchange bytes of accumulatorn,z

Load/Store Instructions

InstructionDescription
LDALoad accumulator from memory
LDXLoad register X from memory
LDYLoad register Y from memory
STAStore accumulator in memory
STXStore register X in memory
STYStore register Y in memory
STZStore zero in memory

Transfer Instructions

Instruction Description Flags affected
TAX Transfer Accumulator to index register X n,z
TAY Transfer Accumulator to index register Y n,z
TCD Transfer 16-bit Accumulator to Direct Page register n,z
TCS Transfer 16-bit Accumulator to Stack Pointer none
TDC Transfer Direct Page register to 16-bit Accumulator n,z
TSC Transfer Stack Pointer to 16-bit Accumulator n,z
TSX Transfer Stack Pointer to index register X n,z
TSY (non-existent) Transfer Stack Pointer to index register Y n,z
TXA Transfer index register X to Accumulator n,z
TXS Transfer index register X to Stack Pointer none
TXY Transfer index register X to index register Y n,z
TYA Transfer index register Y to Accumulator n,z
TYX Transfer index register Y to index register X n,z

Branch Instructions

Instruction Description
BCCBranch if Carry flag is clear (C=0)
BCSBranch if Carry flag is set (C=1)
BNEBranch if not equal (Z=0)
BEQBranch if equal (Z=1)
BPLBranch if plus (N=0)
BMIBranch if minus (N=1)
BVCBranch if overflow flag is clear (V=0)
BVSBranch if overflow flag is set (V=1)
BRABranch Always (unconditional)
BRLBranch Always Long (unconditional)

Jump and call instructions

InstructionDescription
JMPJump
JMLJump long
JSRJump and save return address
JSLJump long and save return address
RTSReturn from subroutine
RTLReturn long from subroutine

Interrupt instructions

InstructionDescription
BRKGenerate software interrupt
COPGenerate coprocessor interrupt
RTIReturn from interrupt
STPStop processor until RESET
WAIWait for hardware interrupt

P Flag instructions

InstructionDescription
CLCClear carry flag
CLDSelect binary arithmetic
CLIEnable interrupt requests
CLVClear overflow flag
REPReset status bits (for example REP #%00100000 clears the M flag)
SECSet carry flag
SEDSelect decimal arithmetic
SEPSet status bits (for example SEP #%00010000 sets the X flag)
SEIDisable interrupt requests
XCEExchange carry flag with emulation flag

Stack Instructions

InstructionDescription
PHAPush Accumulator Push instructions
PHXPush index register X
PHYPush index register Y
PHDPush direct page register
PHBPush data bank register
PHKPush Program Bank Register
PHPPush processor status
PEAPush effective address
PEIPush effective indirect address
PERPush effective relative address
PLAPull Accumulator Pull instructions
PLXPull index register X
PLYPull index register Y
PLPPull processor status
PLDPull direct page register
PLBPull data bank register

Addressing modes

ModeExample
Implied PHB
Immediate[MemoryFlag] AND #1 or 2 bytes
Immediate[IndexFlag] LDX #1 or 2 bytes
Immediate[8-Bit] SEP #byte
Relative BEQ byte (signed)
Relative long BRL 2bytes (signed)
Direct AND byte
Direct indexed (with X) AND byte, x
Direct indexed (with Y) AND byte, y
Direct indirect AND (byte)
Direct indexed indirect AND (byte, x)
Direct indirect indexed AND (byte), y
Direct indirect long AND [byte]
Direct indirect indexed long AND [byte], y
Absolute AND 2bytes
Absolute indexed (with X) AND 2bytes, x
Absolute indexed (with Y) AND 2bytes, y
Absolute long AND 3bytes
Absolute indexed long AND 3bytes, x
Stack relative AND byte, s
Stack relative indirect indexed AND (byte, s), y
Absolute indirect JMP (2bytes)
Absolute indirect long JML [3bytes]
Absolute indexed indirect JMP/JSR (2bytes,x)
Implied accumulator INC
Block move MVN/MVP byte, byte

External links

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.