Equivalents to 6502 instructions

From GbdevWiki
Jump to: navigation, search

Many new Game Boy programmers have experience on a platform with a 6502 family (6502, 6507, 6510, 65C02, 65816, or HuC6280) processor. These include Apple II, Atari 8-bit (2600 VCS, 800, 5200, 7800 ProSystem, Lynx), Nintendo (NES/Famicom, Super NES/Super Famicom), and TurboGrafx-16/PC Engine. To help these programmers adapt, this table lists the closest opcode in the Game Boy CPU to each instruction in a WDC/Rockwell 65C02 CPU.

65C02 instruction SM83 instruction Notes
adc adc See also add
and and Clears carry
asl sla, add a It always stood for Add to SeLf
bbr bit then jr z
bbs bit then jr nz
bcc jr nc
bcs jr c
beq jr z
bit bit Tests the argument against a given bit, not the bits set in A
bmi bit 7 then jr nz
bne jr nz
bpl bit 7 then jr z If using to test a counter for wrapping from $00 to $FF, dec b then jr nz is more commonly used.
bra jr
brk rst
bvc No direct equivalent Replacement uses xor and bit 7
bvs No direct equivalent
clc scf then ccf or a also clears Z. Less needed in general because add exists.
cld No direct equivalent Skip daa after add or sub
cli ei Also enables vblank if set in LCDC, as Game Boy does not use NMI
clv No direct equivalent No SO pin. If using with bvc to simulate bra, use jr without a condition.
cmp cp Carry sense is inverted
cpx No direct equivalent Load a value into A and compare it to B, C, etc.
cpy No direct equivalent
dec dec
dex dec b
dey dec c
eor xor Clears carry
inc inc
inx inc b
iny inc c
jmp jp Can be made conditional
jsr call
lda ld a Does not change Z
ldx ld b Does not change Z; accessing arrays is very different
ldy ld c
lsr srl See also sra which copies bit 7 to carry first
nop nop
ora or Clears carry
pha push af Only pairs of registers can be pushed or popped. BC, DE, and HL are more commonly pushed or popped.
php push af
phx push bc
phy push bc
pla pop af
plp pop af
plx pop bc
ply pop bc
rol rla, rl, adc a See also rlc which copies bit 7 to carry first
rmb res
ror rra, rr See also rrc which copies bit 0 to carry first
rti pop af then reti Interrupt handlers do not automatically push flags.
rts ret Can be made conditional. See also jp hl
sbc sbc Carry sense is inverted; see also sub
sec scf
sed No direct equivalent Use daa after add or sub
sei di Disables vblank, as Game Boy does not use NMI
smb set
sta ld [destination],a
stx ld [hl], b There are two main ways for data to get in and out of registers: through A or through [HL].
sty ld [hl], c
stz xor a then ld [destination],a Sets Z, clears carry and A
tax ld b, a Does not change Z
tay ld c, a Does not change Z
trb res place, [hl]
tsb set place, [hl]
tsx ld hl, sp+0 Does not change Z
txa ld a, b Does not change Z
txs ld sp, hl
tya ld a, c Does not change Z
wai halt