Opcodes list/description

From SMWiki

Jump to: navigation, search

This section will describe 65c816 opcodes; opcodes that aren't functional on the Ricoh 5A22 won't be described in detail.

Contents

[edit] Transfer

These opcodes transfer data between the register or memory; most of them are just 'transfer A to B', so they won't be described in detail.

[edit] LDA

LoaD Accumulator

Store the value of the operand in the accumulator.

Example:

        LDA #$18    ;A:0000 $7E1337 = $0020
        NOP         ;A:0018 $7E1337 = $0020
        LDA $7E1337 ;A:0018 $7E1337 = $0020
        NOP         ;A:0020 $7E1337 = $0020

[edit] LDX

LoaD X

Store the value of the operand into X.

[edit] LDY

LoaD Y

Store the value of the operand into Y.

[edit] STA

STore Accumulator

Store the accumulator into the operand.

[edit] STX

STore X

Store X into the operand.

[edit] STY

STore Y

Store Y into the operand.

[edit] STZ

STore Zero

Store zero (00) in the operand.

[edit] PHA

PusH Accumulator

Store accumulator to the stack.


[edit] PHX

PusH X

Store X to the stack.

[edit] PHY

PusH Y

Store Y to the stack.

[edit] PHP

PusH Proccesor flags

Store processors flags to the stack.

[edit] PHK

PusH program banK

Store the current bank to the stack.

[edit] PHB

PusH data Bank

Store the value of data bank register to the stack.

[edit] PHD

PusH Direct page

Store the value of the direct page register to the stack.

[edit] PEA

Push Effective Adress

Store the value in the operand to the stack.

[edit] PLA

PuLl Accumulator

Load the value of the accumulator from the stack.

[edit] PLX

PuLl X

Load X from the stack.

[edit] PLY

PuLl Y

Load Y from the stack.

[edit] PLB

PuLl data Bank register

Load the value of the data bank register from the stack.

[edit] PLD

PuLl Direct page register

Load the value of the direct page register from the stack.

[edit] PLP

PuLl Processor flags

Load the processor flags from the stack.

[edit] TAX

Transfer Accumulator to X

[edit] TAY

Transfer Accumulator to Y

[edit] TXA

Transfer X to Accumulator

[edit] TXY

Transfer X to Y

[edit] TYA

Transfer Y to Accumulator

[edit] TYX

Transfer Y to X

[edit] TCD

Transfer aCcumulator to Direct page register

[edit] TDC

Transfer Direct page register to aCcumulator

[edit] TCS

Transfer aCcumulator to Stack pointer

[edit] TXS

Transfer X to Stack pointer

[edit] TSC

Transfer Stack pointer to aCcumulator

[edit] TSX

Transfer Stack pointer to aCcumulator

[edit] XBA

EXchange the high and low Byte of the Accumulator

[edit] XCE

EXchange Carry and Emulation

This opcode is the only way to access the 'hidden' 6502 emulation flag. The emulation flag can easily be set with the following code:

             SEC
             XCE

or be cleared using the following:

             CLC
             XCE

While in emulation mode, the accumulator, X and Y register are forced to be 8-bit and one of the processor flag is used to indicate IRQ. It also uses different vectors for interrupt.

[edit] MVP

MoVe Positive

MVP is a rather complex transfer instruction, its use the X register as the 2 low byte of the source address, the Y as the 2 low byte of the destination, the accumulator as the number of byte to transfer and the operand as both the bank of the source and destination.

Example:

              MVP $7E, 7F; A:0200 X:2000 Y:5000 ;this will transfer $200 byte from 7E2000 to 7F5000

[edit] MVN

MoVe Negative

Exactly like MVP, except that the data are transfered in another direction.

[edit] Math

These opcodes perform simple math operations between values.

[edit] ADC

ADd with Carry

Adds the operand to the accumulator. If carry is set, 1 is also added (use with CLC for pure addition).

exemple:

        CLC      ; A:0010
        ADC #$20 ; A:0010
        SEC      ; A:0030
        ADC #$01 ; A:0030
        nop      ; A:0032

[edit] SBC

SuBtract with Carry

Subtracts the operand from the accumulator. If carry is clear, 1 is also subtracted (use with SEC for pure subtraction).

[edit] INC

INCrease value

Adds 1 to the operand.

[edit] INX

INcrease X by 1

[edit] INY

INcrease Y by 1

[edit] DEC

DECrease value

Subtracts 1 from the operand.

[edit] DEX

DEcrease X by 1

[edit] DEY

DEcrease Y by 1


[edit] AND

AND accumulator and memory

AND performs a binary AND with the operand and accumulator (It's very useful to check data stored as a bit, such as the 'Button is pressed' flag).

example:

        AND #$21       ;A:0022 = %00100010
        BEQ somewhere  ;A:0020 = %00100000

[edit] ASL

Left shift memory

ASL performs a binary left shift to the operand (useful for a quick *2 multiplication).

example:

        ASL a          ;A:0020
        STA Somewhere  ;A:0040

[edit] LSR

Right shift memory

LSR performs a binary right shift to the operand.


[edit] ROL

ROtate Left

Performs a binary rotate left to the operand (carry flag is used as either 9th or 17th bit depending of the size of the accumulator)

Example:

            ROL ;A:4000 M=0
            SEC ;A:8000 C=1
            ROL 
                ;A:0001


[edit] ROR

ROtate Right

Performs a binary rotate right to the operand (carry flag is used as either 9th or 17th bit depending of the size of the accumulator).

[edit] CMP

CoMPare accumulator with memory

Subtract the accumulator with the operand and set/clear the flag accordingly. Example:

         LDA #$20 
         CMP #$20 ; 20-20=0, this will set the zero flag and clear the negative and carry flag

[edit] BIT

BIts Test

Subtract the accumulator with the operand and set/clear the flag accordingly.

Example:

       BIT #$20   ; A:0010 (Z=1 C=0 N=0 since $10 AND $20 = $00)

[edit] TSB

Test and Set Bits

This perform a binary OR with the accumulator and the oprand, the result is stored in the operand

[edit] TRB

Test and Reset Bits

This perform a binary NOT to the accumulator, then a binary AND with the oprand, the result is stored in the operand


[edit] Flow

These opcodes control the flow of the program.

[edit] JMP

JuMP

jump to the adress in the operand, the adress used is 16-bit wide, the current bank stay the same

exemple:

$02/A892:             JMP $9000 ;will jump to $02/9000

[edit] JML

JuMp Long

jump to the adress in the operand, the adress used is 24-bit wide

$02/A895:             JML $15B000  ;will jump to $15/B000

[edit] JSR

Jump to SubRoutine

Work like JMP, but push the lowest 16 bit of the current adress to the stack, it's meant to be used with RTS

[edit] JSL

Jump to Subroutine Long

Work like JSR, but push the whole adress to the stack, it's meant to be used with RTL

[edit] RTS

ReTurn from Subroutine

Pull the lowest 16 bit of adress from the stack

exemple:

 $01/8000:         JSR $D000 ;go to $01D000 and push $8003 to the stack
 $01/D000:         RTS       ;pull $8003 from the stack and jump to it
 $01/8003:

[edit] RTL

ReTurn from Subroutine Long

Pull the adress from the stack

exemple:

 $01/8000:         JSL $1A9000 ;go to $01D000 and push $018004 to the stack
 $1A/9000:         RTL       ;pull $018004 from the stack and jump to it
 $01/8004:

[edit] RTI

ReTurn from Interrupt

[edit] BCC

Branch if Carry Clear

Jump to a relative address if the carry flag is cleared.

[edit] BCS

Branch if Carry Set

Jump to a relative address if the carry flag is set.

[edit] BEQ

Branch if EQual

Jump to a relative address if the zero flag is set.

[edit] BNE

Branch if Not Equal

Jump to a relative address if the zero flag is clear.

[edit] BMI

Branch if result MInus

[edit] BPL

Branch if result PLus

[edit] BVC

Branch if Overflow Clear

[edit] BVS

Branch if Overflow Set

Personal tools