Home | Contribute |
This is a list of operation codes for the Game Boy, or how Game Lad tries to emulate them. Stop mode is not supported. Beside that, no bugs are known (or listed in the Bug List).
Operand: dest, src
reg8 | a, b, c, d, e, h, l |
n | 3 bit immediate data |
nn | 8 bit immediate data |
nnnn | 16 bit immediate data |
disp | 8 bit signed immediate data |
[ ] | address |
z | Zero Flag |
n | Subtract Flag |
h | Half-Carry Flag |
c | Carry Flag |
| | inclusive or |
^ | exclusive or |
& | and |
<< | left shift |
>> | right shift |
Mnemonic | Operand | Cycles | Flags | Operation performed |
---|---|---|---|---|
NOP | 4 | |||
LD | reg8, reg8 | 4 | dest = src | |
reg8, [hl] | 8 | |||
[hl], reg8 | 8 | |||
reg8, nn | 8 | |||
[hl], nn | 12 | |||
a, [bc] | 8 | |||
a, [de] | ||||
[bc], a | 8 | |||
[de], a | ||||
[nnnn], a | 16 | |||
a, [nnnn] | 16 | |||
[0xFF00 + nn], a | 12 | |||
[0xFF00 + c], a | 8 | |||
a, [0xFF00 + nn] | 12 | |||
a, [0xFF00 + c] | 8 | |||
bc, nnnn | 12 | |||
de, nnnn | ||||
hl, nnnn | ||||
sp, nnnn | ||||
[nnnn], sp | 20 | |||
hl, sp + disp | 12 | |||
sp, hl | 8 | |||
LDI | a, [hl] | 8 | dest = src hl = hl + 1 | |
[hl], a | 8 | |||
LDD | a, [hl] | 8 | dest = src hl = hl - 1 | |
[hl], a | 8 | |||
INC | bc | 8 | dest = dest + 1 | |
de | ||||
hl | ||||
sp | ||||
reg8 | 4 | z dest + 1 = 0 n 0 h (dest & 0x0F) + 1 > 0x0F |
||
[hl] | 12 | |||
DEC | bc | 8 | dest = dest - 1 | |
de | ||||
hl | ||||
sp | ||||
reg8 | 4 | z dest - 1 = 0 n 1 h !(dest & 0x0F) |
||
[hl] | 12 | |||
ADD | hl, bc | 8 | z dest + src = 0 n 0 h (dest & 0x0FFF) + (src & 0x0FFF) > 0x0FFF c dest + src > 0xFFFF |
dest = dest + src |
hl, de | ||||
hl, hl | ||||
hl, sp | ||||
a, reg8 | 4 | z dest + src = 0 n 0 h (dest & 0x0F) + (src & 0x0F) > 0x0F c dest + src > 0xFF | ||
a, [hl] | 8 | |||
a, nn | 8 | |||
sp, disp | 16 | z 0 n 0 h 0 c dest + src > 0xFFFF | ||
ADC | a, reg8 | 4 | z dest + src + carry = 0 n 0 h (dest & 0x0F) + (src & 0x0F) + carry > 0x0F c dest + src + carry > 0xFF |
if carry: dest = dest + src + 1 else: dest = dest + src |
a, [hl] | 8 | |||
a, nn | 8 | |||
SUB | a, reg8 | 4 | z dest - src = 0 n 1 h dest & 0x0F < src & 0x0F c dest - src < 0 |
dest = dest - src |
a, [hl] | 8 | |||
a, nn | 8 | |||
SBC | a, reg8 | 4 | z dest - src - carry = 0 n 1 h dest & 0x0F < (src - carry) & 0x0F c dest - src - carry < 0 |
if carry: dest = dest - src - 1 else: dest = dest - src |
a, [hl] | 8 | |||
a, nn | 8 | |||
AND | a, reg8 | 4 | z dest & src = 0 n 0 h 1 c 0 |
dest = dest & src |
a, [hl] | 8 | |||
a, nn | 8 | |||
XOR | a, reg8 | 4 | z dest ^ src = 0 n 0 h 0 c 0 |
dest = dest ^ src |
a, [hl] | 8 | |||
a, nn | 8 | |||
OR | a, reg8 | 4 | z dest | src = 0 n 0 h 0 c 0 |
dest = dest | src |
a, [hl] | 8 | |||
a, nn | 8 | |||
CP | a, reg8 | 4 | z dest = src n 1 h (dest & 0x0F) < (src & 0x0F) c dest < src |
sets flags |
a, [hl] | 8 | |||
a, nn | 8 | |||
RLCA | 4 | z 0 n 0 h 0 c a & 0x80 |
a = (a << 1) | (a >> 7) | |
RLC | reg8 | 8 | z dest = 0 n 0 h 0 c dest & 0x80 |
dest = (dest << 1) | (dest >> 7) |
[hl] | 16 | |||
RRCA | 4 | z 0 n 0 h 0 c a & 0x01 |
a = (a >> 1) | (a << 7) | |
RRC | reg8 | 8 | z dest = 0 n 0 h 0 c dest & 0x01 |
dest = (dest >> 1) | (dest << 7) |
[hl] | 16 | |||
RLA | 4 | z 0 n 0 h 0 c a & 0x80 |
if carry: a = (a << 1) | 0x01 else: a = a << 1 | |
RL | reg8 | 8 | z dest = 0 n 0 h 0 c dest & 0x80 |
if carry: dest = (dest << 1) | 0x01 else: dest = dest << 1 |
[hl] | 16 | |||
RRA | 4 | z 0 n 0 h 0 c a & 0x01 |
if carry: a = (a >> 1) | 0x80 else: a = a >> 1 | |
RR | reg8 | 8 | z dest = 0 n 0 h 0 c dest & 0x01 |
if carry: dest = (dest >> 1) | 0x80 else: dest = dest >> 1 |
[hl] | 16 | |||
SLA | reg8 | 8 | z dest & 0x7F = 0 n 0 h 0 c dest & 0x80 |
dest = dest << 1 |
[hl] | 16 | |||
SRA | reg8 | 8 | z dest = 0 n 0 h 0 c dest & 0x01 |
dest = (dest >> 1) | (dest & 0x80) |
[hl] | 16 | |||
SRL | reg8 | 8 | z dest & 0xFE = 0 n 0 h 0 c dest & 0x01 |
dest = dest >> 1 |
[hl] | 16 | |||
SWAP | reg8 | 8 | z dest = 0 n 0 h 0 c 0 |
dest = (dest >> 4) | (dest << 4) |
[hl] | 16 | |||
BIT | n, reg8 | 8 | z dest & (1 << n) = 0 n 0 h 1 |
sets flags |
n, [hl] | 16 | |||
RES | n, reg8 | 8 | dest = dest & ~(1 << n) | |
n, [hl] | 16 | |||
SET | n, reg8 | 8 | dest = dest | (1 << n) | |
n, [hl] | 16 | |||
CPL | 4 | n 1 h 1 |
a = ~a | |
SCF | 4 | n 0 h 0 c 1 |
sets flags | |
CCF | 4 | n 0 h 0 c !c |
sets flags | |
DAA | 4 | z result is zero h 0 |
Decimal Adjust Ackumulator | |
JR | disp | 12 | pc = pc + disp | |
nz, disp | 12 if jump, else 8 | if !zero: pc = pc + disp | ||
z, disp | if zero: pc = pc + disp | |||
nc, disp | if !carry: pc = pc + disp | |||
c, disp | if carry: pc = pc + disp | |||
JP | nnnn | 16 | pc = nnnn | |
nz, nnnn | 16 if jump, else 12 | if !zero: pc = nnnn | ||
z, nnnn | if zero: pc = nnnn | |||
nc, nnnn | if !carry: pc = nnnn | |||
c, nnnn | if carry: pc = nnnn | |||
CALL | nnnn | 24 | push pc onto stack pc = nnnn | |
nz, nnnn | 24 if call, else 12 | if !zero: push pc onto stack pc = nnnn | ||
z, nnnn | if zero: push pc onto stack pc = nnnn | |||
nc, nnnn | if !carry: push pc onto stack pc = nnnn | |||
c, nnnn | if carry: push pc onto stack pc = nnnn | |||
RST | nn | 16 | push pc onto stack pc = nn | |
RET | 16 | removes pc from stack | ||
nz | 20 if return, else 8 | if !zero: removes pc from stack | ||
z | if zero: removes pc from stack | |||
nc | if !carry: removes pc from stack | |||
c | if carry: removes pc from stack | |||
RETI | 16 | removes pc from stack and enables interrupts after the next instruction | ||
PUSH | af | 16 | push dest onto stack | |
bc | ||||
de | ||||
hl | ||||
POP | af | 12 | removes dest from stack | |
bc | ||||
de | ||||
hl | ||||
EI | 4 | enables interrupts after the next instruction | ||
DI | 4 | disables interrupts | ||
HALT | 4 | if ie: Halts processor until an interrupt occurs. | ||
STOP | 4 | Switches between normal and double speed if [0xFF4D] & 0x80 Else, the Game Boy is put in stop mode. |