🎮
Assembly for the SNES
  • Introduction
  • Getting started
  • Contributing
  • The fundamentals
    • Hexadecimal
    • Binary
    • The SNES memory
    • The SNES registers
    • Addressing modes
    • Little-endian
    • Glossary
  • The basics
    • Loading and storing
    • Shorter addresses
    • 8-bit and 16-bit mode
    • Comparing, branching, labels
    • Jumping to subroutines
  • Collection of values
    • Tables and indexing
    • The stack
    • Copying data
  • Processor flags and registers
    • The processor flags
    • Changing the processor flags
    • Transfers
    • Stack pointer register
  • Mathemathics and logic
    • Arithmetic operations
    • Bit shifting operations
    • Bitwise operations
    • Hardware math
  • Deep dives
    • Addressing modes revisted
    • Miscellaneous opcodes
    • Machine cycles
    • Hardware vectors
    • Techniques
    • Common assembler syntax
    • Programming cautions
Powered by GitBook
On this page
  • NOP
  • XBA
  • WAI
  • STP
  • BRK
  • COP
  • WDM

Was this helpful?

  1. Deep dives

Miscellaneous opcodes

PreviousAddressing modes revistedNextMachine cycles

Last updated 3 years ago

Was this helpful?

This chapter explains opcodes which don't really fit in any other chapter.

NOP

Opcode

Full name

Explanation

NOP

No operation

Does absolutely nothing

It is often used to disable existing opcodes in a ROM without shifting around the machine code. It can also be used to give time for the to do their work.

XBA

Opcode

Full name

Explanation

XBA

Exchange B and A

Swaps the high and the low bytes of the A register, regardless of the register size.

Here's an example:

LDA #$0231         ; A = $0231
XBA                ; A is now $3102

This even works with 8-bit A, as the high byte of A is "hidden" rather than set to $00:

LDA #$12           ; A = $xx12
XBA                ; A = $12xx
LDA #$05           ; A = $1205

WAI

Opcode

Full name

Explanation

WAI

Wait for interrupt

Halts the SNES CPU until either an NMI or IRQ occurs.

Exactly what it says, it halts the SNES CPU until either an NMI or IRQ (both are interrupts) occurs. Practically speaking, the opcode loops itself infinitely until an interrupt occurs.

STP

Opcode

Full name

Explanation

STP

Stop the clock

The "clock" being the SNES CPU in this case, it halts the CPU completely until either a soft or hard reset occurs.

Exactly what it says, it stops the SNES CPU until you hit reset or power cycle the SNES. It does lower the power consumption of the SNES, if the couple of cents it'll shave off your power bill means that much to you.

BRK

Opcode

Full name

Explanation

BRK

Software break

Causes a break to occur

BRK #$02

The parameter is not used for anything in particular, but if you write a meaningful "catch" to the BRK, you could probably read what the value of the BRK was supposed to be, and do certain things depending on the value.

When the BRK opcode is executed, the following events happen:

  • First, the (24-bit) address of the instruction after BRK #$xx is pushed onto the stack

  • Then, the (8-bit) processor flag register is pushed onto the stack.

  • The interrupt disable flag is set (akin to SEI)

  • The decimal mode flag is cleared (akin to CLD)

  • The program bank register is cleared to $00

  • The program counter is loaded from the break vector. In other words, the code jumps to the address at the break vector.

COP

Opcode

Full name

Explanation

COP

Coprocessor empowerment

Similar effects as BRK, as the SNES has no coprocessor to empower.

COP #$04

The parameter is not used for anything in particular, but if you write a meaningful "catch" to the COP, you could probably read what the value of the COP was supposed to be, and do certain things depending on the value.

When the COP opcode is executed, the following events happen:

  • First, the (24-bit) address of the instruction after COP #$xx is pushed onto the stack

  • Then, the (8-bit) processor flag register is pushed onto the stack.

  • The interrupt disable flag is set (akin to SEI)

  • The decimal mode flag is cleared (akin to CLD)

  • The program bank register is cleared to $00

  • The program counter is loaded from the COP hardware vector. In other words, the code jumps to the address at the COP hardware vector.

WDM

Opcode

Full name

Explanation

WDM

Reserved for future expansion

Does absolutely nothing

WDM #$01

This opcode has the same effect as NOP however. Therefore, it does nothing.

This opcode causes the SNES to jump to the . It also takes a byte parameter. Example usage:

If the emulators are made properly, the opcode BRK makes debuggers snap. You could also program the break vector to do meaningful things. In fact, on SMWCentral, ; it shows debug information about the crash.

This opcode causes the SNES to jump to the . It also takes a byte parameter. Example usage:

WDM stands for "", who designed the 65c816. This opcode was reserved for the possibility of multi-byte opcodes. Therefore, this opcode actually takes a parameter. Example:

math hardware registers
break vector
p4plus2 released a patch which does exactly this
COP hardware vector
William (Bill) David Mensch, Jr.