GBZ80(7)
๐ NAME ๐
gbz80 โ Game Boy CPU instruction reference. okay so bestie, this is gbz80(7), the glow-up reference for the Game Boy CPU instructions, and we're getting into it ๐
.
โจ DESCRIPTION โจ
okay so here's the tea: this is the list of instructions supported by rgbasm(1), including a short description, the number of bytes needed to encode them, and the number of CPU cycles at 1MHz (or 2MHz in GBC double speed mode) needed to complete them. no cap, every byte and cycle matters ๐.
Instructions are documented according to the syntax accepted by rgbasm(1), which does not always match one-to-one with the way instructions are encoded: https://gbdev.io/gb-opcodes/optables/.
Note: All arithmetic and logic instructions that use register A as a destination can omit the destination, since it is assumed to be register A by default. So the following two lines have the same effect:
OR A,B
OR B
Furthermore, the CPL instruction can take an optional A destination, since it can only be register A. So the following two lines have the same effect:
CPL
CPL A
๐ง LEGEND ๐ง
List of abbreviations used in this document. lowkey essential, bestie ๐ซถ.
r8โ Any of the 8-bit registers (A,B,C,D,E,H,L).r16โ Any of the general-purpose 16-bit registers (BC,DE,HL).n8โ 8-bit integer constant (signed or unsigned,-128to255).n16โ 16-bit integer constant (signed or unsigned,-32768to65535).e8โ 8-bit signed offset (-128to127).u3โ 3-bit unsigned bit index (0to7, with0as the least significant bit).ccโ A condition code:Zโ Execute if Z is set.NZโ Execute if Z is not set.Cโ Execute if C is set.NCโ Execute if C is not set.
vecโ An RST vector (0x00,0x08,0x10,0x18,0x20,0x28,0x30, and0x38).
๐ INSTRUCTION OVERVIEW ๐
๐ Load instructions ๐
LD r8,r8LD r8,n8LD r16,n16LD [HL],r8LD [HL],n8LD r8,[HL]LD [r16],ALD [n16],ALDH [n16],ALDH [C],ALD A,[r16]LD A,[n16]LDH A,[n16]LDH A,[C]LD [HLI],ALD [HLD],ALD A,[HLI]LD A,[HLD]
๐งฎ 8-bit arithmetic instructions ๐งฎ
ADC A,r8ADC A,[HL]ADC A,n8ADD A,r8ADD A,[HL]ADD A,n8CP A,r8CP A,[HL]CP A,n8DEC r8DEC [HL]INC r8INC [HL]SBC A,r8SBC A,[HL]SBC A,n8SUB A,r8SUB A,[HL]SUB A,n8
๐งฎ 16-bit arithmetic instructions ๐งฎ
ADD HL,r16DEC r16INC r16
๐ฆ Bitwise logic instructions ๐ฆ
AND A,r8AND A,[HL]AND A,n8CPLOR A,r8OR A,[HL]OR A,n8XOR A,r8XOR A,[HL]XOR A,n8
๐ Bit flag instructions ๐
BIT u3,r8BIT u3,[HL]RES u3,r8RES u3,[HL]SET u3,r8SET u3,[HL]
๐ Bit shift instructions ๐
RL r8RL [HL]RLARLC r8RLC [HL]RLCARR r8RR [HL]RRARRC r8RRC [HL]RRCASLA r8SLA [HL]SRA r8SRA [HL]SRL r8SRL [HL]SWAP r8SWAP [HL]
๐ซ Jumps and subroutine instructions ๐ซ
CALL n16CALL cc,n16JP HLJP n16JP cc,n16JR n16JR cc,n16RET ccRETRETIRST vec
๐ฉ Carry flag instructions ๐ฉ
CCFSCF
๐ฅ Stack manipulation instructions ๐ฅ
ADD HL,SPADD SP,e8DEC SPINC SPLD SP,n16LD [n16],SPLD HL,SP+e8LD SP,HLPOP AFPOP r16PUSH AFPUSH r16
โก Interrupt-related instructions โก
DIEIHALT
๐ Miscellaneous instructions ๐
DAANOPSTOP
๐ INSTRUCTION REFERENCE ๐
๐
ADC A,r8 ๐
Add the value in r8 plus the carry flag to A. bestie, that carry flag is coming along for the ride โจ.
Cycles: 1
Bytes: 1
Flags:
Zโ Set if result is0.Nโ0.Hโ Set if overflow from bit 3.Cโ Set if overflow from bit 7.
๐
ADC A,[HL] ๐
Add the byte pointed to by HL plus the carry flag to A.
Cycles: 2
Bytes: 1
Flags: See ADC A,r8.
๐
ADC A,n8 ๐
Add the value n8 plus the carry flag to A.
Cycles: 2
Bytes: 2
Flags: See ADC A,r8.
๐
ADD A,r8 ๐
Add the value in r8 to A.
Cycles: 1
Bytes: 1
Flags:
Zโ Set if result is0.Nโ0.Hโ Set if overflow from bit 3.Cโ Set if overflow from bit 7.
๐
ADD A,[HL] ๐
Add the byte pointed to by HL to A.
Cycles: 2
Bytes: 1
Flags: See ADD A,r8.
๐
ADD A,n8 ๐
Add the value n8 to A.
Cycles: 2
Bytes: 2
Flags: See ADD A,r8.
๐
ADD HL,r16 ๐
Add the value in r16 to HL.
Cycles: 2
Bytes: 1
Flags:
Nโ0.Hโ Set if overflow from bit 11.Cโ Set if overflow from bit 15.
๐
ADD HL,SP ๐
Add the value in SP to HL.
Cycles: 2
Bytes: 1
Flags: See ADD HL,r16.
๐
ADD SP,e8 ๐
Add the signed value e8 to SP.
Cycles: 4
Bytes: 2
Flags:
Zโ0.Nโ0.Hโ Set if overflow from bit 3.Cโ Set if overflow from bit 7.
๐
AND A,r8 ๐
Set A to the bitwise AND between the value in r8 and A.
Cycles: 1
Bytes: 1
Flags:
Zโ Set if result is0.Nโ0.Hโ1.Cโ0.
๐
AND A,[HL] ๐
Set A to the bitwise AND between the byte pointed to by HL and A.
Cycles: 2
Bytes: 1
Flags: See AND A,r8.
๐
AND A,n8 ๐
Set A to the bitwise AND between the value n8 and A.
Cycles: 2
Bytes: 2
Flags: See AND A,r8.
๐
BIT u3,r8 ๐
Test bit u3 in register r8, set the zero flag if bit not set.
Cycles: 2
Bytes: 2
Flags:
Zโ Set if the selected bit is0.Nโ0.Hโ1.
๐
BIT u3,[HL] ๐
Test bit u3 in the byte pointed by HL, set the zero flag if bit not set.
Cycles: 3
Bytes: 2
Flags: See BIT u3,r8.
๐
CALL n16 ๐
Call address n16.
This pushes the address of the instruction after the CALL on the stack, such that RET can pop it later; then, it executes an implicit JP n16.
Cycles: 6
Bytes: 3
Flags: None affected.
๐
CALL cc,n16 ๐
Call address n16 if condition cc is met.
Cycles: 6 taken / 3 untaken
Bytes: 3
Flags: None affected.
๐
CCF ๐
Complement Carry Flag.
Cycles: 1
Bytes: 1
Flags:
Nโ0.Hโ0.Cโ Inverted.
๐
CP A,r8 ๐
ComPare the value in A with the value in r8.
This subtracts the value in r8 from A and sets flags accordingly, but discards the result.
Cycles: 1
Bytes: 1
Flags:
Zโ Set if result is0.Nโ1.Hโ Set if borrow from bit 4.Cโ Set if borrow (i.e. ifr8 > A).
๐
CP A,[HL] ๐
ComPare the value in A with the byte pointed to by HL.
This subtracts the byte pointed to by HL from A and sets flags accordingly, but discards the result.
Cycles: 2
Bytes: 1
Flags: See CP A,r8.
๐
CP A,n8 ๐
ComPare the value in A with the value n8.
This subtracts the value n8 from A and sets flags accordingly, but discards the result.
Cycles: 2
Bytes: 2
Flags: See CP A,r8.
๐
CPL ๐
ComPLement accumulator (A = ~A); also called bitwise NOT.
Cycles: 1
Bytes: 1
Flags:
Nโ1.Hโ1.
๐
DAA ๐
Decimal Adjust Accumulator.
Designed to be used after performing an arithmetic instruction (ADD, ADC, SUB, SBC) whose inputs were in Binary-Coded Decimal (BCD), adjusting the result to likewise be in BCD.
The exact behavior of this instruction depends on the state of the subtract flag N:
If the subtract flag N is set:
- Initialize the adjustment to
0. - If the half-carry flag
His set, then add$6to the adjustment. - If the carry flag is set, then add
$60to the adjustment. - Subtract the adjustment from
A.
If the subtract flag N is not set:
- Initialize the adjustment to
0. - If the half-carry flag
His set orA & $F > $9, then add$6to the adjustment. - If the carry flag is set or
A > $99, then add$60to the adjustment and set the carry flag. - Add the adjustment to
A.
Cycles: 1
Bytes: 1
Flags:
Zโ Set if result is0.Hโ0.Cโ Set or unaffected depending on the operation.
๐
DEC r8 ๐
Decrement the value in register r8 by 1.
Cycles: 1
Bytes: 1
Flags:
Zโ Set if result is0.Nโ1.Hโ Set if borrow from bit 4.
๐
DEC [HL] ๐
Decrement the byte pointed to by HL by 1.
Cycles: 3
Bytes: 1
Flags: See DEC r8.
๐
DEC r16 ๐
Decrement the value in register r16 by 1.
Cycles: 2
Bytes: 1
Flags: None affected.
๐
DEC SP ๐
Decrement the value in register SP by 1.
Cycles: 2
Bytes: 1
Flags: None affected.
๐
DI ๐
Disable Interrupts by clearing the IME flag.
Cycles: 1
Bytes: 1
Flags: None affected.
๐
EI ๐
Enable Interrupts by setting the IME flag.
The flag is only set after the instruction following EI.
Cycles: 1
Bytes: 1
Flags: None affected.
๐
HALT ๐
Enter CPU low-power consumption mode until an interrupt occurs.
The exact behavior of this instruction depends on the state of the IME flag, and whether interrupts are pending (i.e. whether [IE] & [IF] is non-zero):
- If the IME flag is set: The CPU enters low-power mode until after an interrupt is about to be serviced. The handler is executed normally, and the CPU resumes execution after the HALT when that returns.
- If the IME flag is not set, and no interrupts are pending: As soon as an interrupt becomes pending, the CPU resumes execution. This is like the above, except that the handler is not called.
okay so picking up right where we left off inside HALT's whole situation:
If the IME flag is not set, and some interrupt is pending: the CPU continues execution after the HALT, but the byte after it is read twice in a row (PC is not incremented, due to a hardware bug).
not me reading the same byte twice because of a hardware bug ๐ญ iconic behavior, honestly.
- Cycles:
- - Bytes: 1
- Flags: none affected
INC r8
Bump the value in register r8 up by 1. Literally just +1 energy.
- Cycles: 1
- Bytes: 1
- Flags:
Zโ set if result is 0.Nโ0Hโ set if overflow from bit 3.
INC [HL]
Increment the byte pointed to by HL by 1. One little byte glow-up.
- Cycles: 3
- Bytes: 1
- Flags: see
INC r8.
INC r16
Increment the value in register r16 by 1.
- Cycles: 2
- Bytes: 1
- Flags: none affected.
INC SP
Increment the value in register SP by 1. Stack pointer gets a little nudge.
- Cycles: 2
- Bytes: 1
- Flags: none affected.
JP n16
Jump to address n16; basically copy n16 straight into PC. Main character relocation.
- Cycles: 4
- Bytes: 3
- Flags: none affected.
JP cc,n16
Jump to address n16 only if condition cc is met. Conditional slay.
- Cycles:
4 taken / 3 untaken - Bytes: 3
- Flags: none affected.
JP HL
Jump to the address in HL; effectively copy the value in register HL into PC.
- Cycles: 1
- Bytes: 1
- Flags: none affected.
JR n16
Relative Jump to address n16.
The target address n16 is encoded as a signed 8-bit offset from the address immediately following the JR instruction, so it must be between -128 and 127 bytes away. For example:
JR Label ; no-op; encoded offset of 0
Label:
JR Label ; infinite loop; encoded offset of -2
- Cycles: 3
- Bytes: 2
- Flags: none affected.
JR cc,n16
Relative Jump to address n16 if condition cc is met.
The target address n16 is encoded as a signed 8-bit offset from the address immediately following the JR instruction, so it must be between -128 and 127 bytes away.
- Cycles:
3 taken / 2 untaken - Bytes: 2
- Flags: none affected.
LD r8,r8
Copy (aka Load) the value in the register on the right into the register on the left.
Storing a register into itself is a no-op; however, some Game Boy emulators interpret LD B,B as a breakpoint, or LD D,D as a debug message (such as BGB: https://bgb.bircd.org/manual.html#expressions).
- Cycles: 1
- Bytes: 1
- Flags: none affected.
LD r8,n8
Copy the value n8 into register r8.
- Cycles: 2
- Bytes: 2
- Flags: none affected.
LD r16,n16
Copy the value n16 into register r16.
- Cycles: 3
- Bytes: 3
- Flags: none affected.
LD [HL],r8
Copy the value in register r8 into the byte pointed to by HL.
- Cycles: 2
- Bytes: 1
- Flags: none affected.
LD [HL],n8
Copy the value n8 into the byte pointed to by HL.
- Cycles: 3
- Bytes: 2
- Flags: none affected.
LD r8,[HL]
Copy the value pointed to by HL into register r8.
- Cycles: 2
- Bytes: 1
- Flags: none affected.
LD [r16],A
Copy the value in register A into the byte pointed to by r16.
- Cycles: 2
- Bytes: 1
- Flags: none affected.
LD [n16],A
Copy the value in register A into the byte at address n16.
- Cycles: 4
- Bytes: 3
- Flags: none affected.
LDH [n16],A
Copy the value in register A into the byte at address n16.
The destination address n16 is encoded as its 8-bit low byte and assumes a high byte of $FF, so it must be between $FF00 and $FFFF.
- Cycles: 3
- Bytes: 2
- Flags: none affected.
LDH [C],A
Copy the value in register A into the byte at address $FF00+C.
- Cycles: 2
- Bytes: 1
- Flags: none affected.
This is sometimes written as LD [$FF00+C],A.
LD A,[r16]
Copy the byte pointed to by r16 into register A.
- Cycles: 2
- Bytes: 1
- Flags: none affected.
LD A,[n16]
Copy the byte at address n16 into register A.
- Cycles: 4
- Bytes: 3
- Flags: none affected.
LDH A,[n16]
Copy the byte at address n16 into register A.
The source address n16 is encoded as its 8-bit low byte and assumes a high byte of $FF, so it must be between $FF00 and $FFFF.
- Cycles: 3
- Bytes: 2
- Flags: none affected.
LDH A,[C]
Copy the byte at address $FF00+C into register A.
- Cycles: 2
- Bytes: 1
- Flags: none affected.
This is sometimes written as LD A,[$FF00+C].
LD [HLI],A
Copy the value in register A into the byte pointed by HL and increment HL afterwards.
- Cycles: 2
- Bytes: 1
- Flags: none affected.
This is sometimes written as LD [HL+],A, or LDI [HL],A.
LD [HLD],A
Copy the value in register A into the byte pointed by HL and decrement HL afterwards.
- Cycles: 2
- Bytes: 1
- Flags: none affected.
This is sometimes written as LD [HL-],A, or LDD [HL],A.
LD A,[HLD]
Copy the byte pointed to by HL into register A, and decrement HL afterwards.
- Cycles: 2
- Bytes: 1
- Flags: none affected.
This is sometimes written as LD A,[HL-], or LDD A,[HL].
LD A,[HLI]
Copy the byte pointed to by HL into register A, and increment HL afterwards.
- Cycles: 2
- Bytes: 1
- Flags: none affected.
This is sometimes written as LD A,[HL+], or LDI A,[HL].
LD SP,n16
Copy the value n16 into register SP.
- Cycles: 3
- Bytes: 3
- Flags: none affected.
LD [n16],SP
Copy SP & $FF to address n16 and SP >> 8 to address n16 + 1.
- Cycles: 5
- Bytes: 3
- Flags: none affected.
LD HL,SP+e8
Add the signed value e8 to SP and copy the result in HL.
- Cycles: 3
- Bytes: 2
- Flags:
Zโ0Nโ0Hโ set if overflow from bit 3.Cโ set if overflow from bit 7.
LD SP,HL
Copy register HL into register SP.
- Cycles: 2
- Bytes: 1
- Flags: none affected.
NOP
No OPeration. The icon of doing absolutely nothing, periodt.
- Cycles: 1
- Bytes: 1
- Flags: none affected.
OR A,r8
Set A to the bitwise OR between the value in r8 and A.
- Cycles: 1
- Bytes: 1
- Flags:
Zโ set if result is 0.Nโ0Hโ0Cโ0
OR A,[HL]
Set A to the bitwise OR between the byte pointed to by HL and A.
- Cycles: 2
- Bytes: 1
- Flags: see
OR A,r8.
OR A,n8
Set A to the bitwise OR between the value n8 and A.
- Cycles: 2
- Bytes: 2
- Flags: see
OR A,r8.
POP AF
Pop register AF from the stack. This is roughly equivalent to the following imaginary instructions:
LD F, [SP] ; See below for individual flags
INC SP
LD A, [SP]
INC SP
- Cycles: 3
- Bytes: 1
- Flags:
Zโ set from bit 7 of the popped low byte.Nโ set from bit 6 of the popped low byte.Hโ set from bit 5 of the popped low byte.Cโ set from bit 4 of the popped low byte.
POP r16
Pop register r16 from the stack. This is roughly equivalent to the following imaginary instructions:
LD LOW(r16), [SP] ; C, E or L
INC SP
LD HIGH(r16), [SP] ; B, D or H
INC SP
- Cycles: 3
- Bytes: 1
- Flags: none affected.
PUSH AF
Push register AF into the stack. This is roughly equivalent to the following imaginary instructions:
DEC SP
LD [SP], A
DEC SP
LD [SP], F.Z << 7 | F.N << 6 | F.H << 5 | F.C << 4
- Cycles: 4
- Bytes: 1
- Flags: none affected.
PUSH r16
Push register r16 into the stack. This is roughly equivalent to the following imaginary instructions:
DEC SP
LD [SP], HIGH(r16) ; B, D or H
DEC SP
LD [SP], LOW(r16) ; C, E or L
- Cycles: 4
- Bytes: 1
- Flags: none affected.
RES u3,r8
Set bit u3 in register r8 to 0. Bit 0 is the rightmost one, bit 7 the leftmost one.
- Cycles: 2
- Bytes: 2
- Flags: none affected.
RES u3,[HL]
Set bit u3 in the byte pointed by HL to 0. Bit 0 is the rightmost one, bit 7 the leftmost one.
- Cycles: 4
- Bytes: 2
- Flags: none affected.
RET
Return from subroutine. This is basically a POP PC (if such an instruction existed). See POP r16 for an explanation of how POP works.
- Cycles: 4
- Bytes: 1
- Flags: none affected.
RET cc
Return from subroutine if condition cc is met.
- Cycles:
5 taken / 2 untaken - Bytes: 1
- Flags: none affected.
RETI
Return from subroutine and enable interrupts. This is basically equivalent to executing EI then RET, meaning that IME is set right after this instruction.
- Cycles: 4
- Bytes: 1
- Flags: none affected.
RL r8
Rotate bits in register r8 left, through the carry flag.
โโ Flags โโ โโโโโโโโ r8 โโโโโโโ
โโโโ C โโโโโ b7 โ ... โ b0 โโโโ
โ โโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- Cycles: 2
- Bytes: 2
- Flags:
Zโ set if result is 0.Nโ0Hโ0Cโ set according to result.
RL [HL]
Rotate the byte pointed to by HL left, through the carry flag.
โโ Flags โโ โโโโโโโ [HL] โโโโโโ
โโโโ C โโโโโ b7 โ ... โ b0 โโโโ
โ โโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- Cycles: 4
- Bytes: 2
- Flags: see
RL r8.
RLA
Rotate register A left, through the carry flag.
โโ Flags โโ โโโโโโโโ A โโโโโโโโ
โโโโ C โโโโโ b7 โ ... โ b0 โโโโ
โ โโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- Cycles: 1
- Bytes: 1
- Flags:
Zโ0Nโ0Hโ0Cโ set according to result.
RLC r8
Rotate register r8 Left Circularly.
โโ Flags โโ โโโโโโโโ r8 โโโโโโโ
โ C โโโโฌโโโ b7 โ ... โ b0 โโโโ
โโโโโโโโโโโ โ โโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโ
- Cycles: 2
- Bytes: 2
- Flags:
Zโ set if result is 0.Nโ0Hโ0Cโ set according to result.
RLC [HL]
Rotate the byte pointed to by HL Left Circularly.
โฆand the rest of the RLC [HL] entry wraps up with the little loop diagram, bestie ๐
โโ Flags โโ โโโโโโโ [HL] โโโโโโ
โ C โโโโฌโโโ b7 โ ... โ b0 โโโโ
โโโโโโโโโโโ โ โโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโ
- Cycles:
4 - Bytes:
2 - Flags: See โ
RLC r8โ
๐ช๏ธ RLCA
Rotate register A Left Circularly โ the bit that falls off the top loops right back around, no carry nonsense involved ๐
โโ Flags โโ โโโโโโโโ A โโโโโโโโ
โ C โโโโฌโโโ b7 โ ... โ b0 โโโโ
โโโโโโโโโโโ โ โโโโโโโโโโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโ
- Cycles:
1 - Bytes:
1 - Flags:
Z=0,N=0,H=0,C= set according to result. ๐ซ
๐ช๏ธ RR r8
Rotate register r8 right, through the carry flag โ so the old carry gets shoved into the top bit on its way round ๐
โโโโโโโโ r8 โโโโโโโ โโ Flags โโ
โโโโ b7 โ ... โ b0 โโโโโ C โโโโ
โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- Cycles:
2 - Bytes:
2 - Flags:
Z= set if result is0,N=0,H=0,C= set according to result โจ
๐ช๏ธ RR [HL]
Same rotation-through-carry energy as above, except it's the byte pointed to by HL getting the makeover, not a register ๐ซถ
โโโโโโโ [HL] โโโโโโ โโ Flags โโ
โโโโ b7 โ ... โ b0 โโโโโ C โโโโ
โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- Cycles:
4 - Bytes:
2 - Flags: See โ
RR r8โ
๐ช๏ธ RRA
Rotate register A right, through the carry flag. A-only version, so it's a speedy little one-cycler ๐
โโโโโโโโ A โโโโโโโโ โโ Flags โโ
โโโโ b7 โ ... โ b0 โโโโโ C โโโโ
โ โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโ โ
โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโ
- Cycles:
1 - Bytes:
1 - Flags:
Z=0,N=0,H=0,C= set according to result โญ
๐ก RRC r8
Rotate register r8 Right Circularly โ straight-up loop, the carry flag is literally just watching ๐
โโโโโโโโ r8 โโโโโโโ โโ Flags โโ
โโโโ b7 โ ... โ b0 โโโโฌโโโ C โ
โ โโโโโโโโโโโโโโโโโโโ โ โโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโ
- Cycles:
2 - Bytes:
2 - Flags:
Z= set if result is0,N=0,H=0,C= set according to result ๐
๐ก RRC [HL]
Rotate the byte pointed to by HL Right Circularly. Same circular vibe, memory flavour ๐ธ
โโโโโโโ [HL] โโโโโโ โโ Flags โโ
โโโโ b7 โ ... โ b0 โโโโฌโโโ C โ
โ โโโโโโโโโโโโโโโโโโโ โ โโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโ
- Cycles:
4 - Bytes:
2 - Flags: See โ
RRC r8โ
๐ก RRCA
Rotate register A Right Circularly. She's iconic, she's one byte, she's one cycle ๐
โโโโโโโโ A โโโโโโโโ โโ Flags โโ
โโโโ b7 โ ... โ b0 โโโโฌโโโ C โ
โ โโโโโโโโโโโโโโโโโโโ โ โโโโโโโโโโโ
โโโโโโโโโโโโโโโโโโโโโโโ
- Cycles:
1 - Bytes:
1 - Flags:
Z=0,N=0,H=0,C= set according to result ๐
๐ RST vec
Call address vec. This is a shorter and faster equivalent to โCALLโ for suitable values of vec โ like the express-lane version of a call, no cap ๐ฅ
- Cycles:
4 - Bytes:
1 - Flags: None affected.
โ SBC A,r8
Subtract the value in r8 and the carry flag from A โ yes, the carry jumps in too, that's literally the whole point ๐
- Cycles:
1 - Bytes:
1 - Flags:
Z= set if result is0N=1H= set if borrow from bit 4C= set if borrow (i.e. if (r8+ carry) > A)
โ SBC A,[HL]
Subtract the byte pointed to by HL and the carry flag from A ๐งฎ
- Cycles:
2 - Bytes:
1 - Flags: See โ
SBC A,r8โ
โ SBC A,n8
Subtract the value n8 and the carry flag from A ๐งฎ
- Cycles:
2 - Bytes:
2 - Flags: See โ
SBC A,r8โ
๐ฉ SCF
Set Carry Flag. That's it, that's the whole instruction, and honestly? Slay ๐
- Cycles:
1 - Bytes:
1 - Flags:
N=0,H=0,C=1(noticeZdoesn't even get a mention here ๐)
๐ง SET u3,r8
Set bit u3 in register r8 to 1. Bit 0 is the rightmost one, bit 7 the leftmost one โ write that down bestie, it comes up constantly ๐
- Cycles:
2 - Bytes:
2 - Flags: None affected.
๐ง SET u3,[HL]
Set bit u3 in the byte pointed by HL to 1. Bit 0 is the rightmost one, bit 7 the leftmost one โจ
- Cycles:
4 - Bytes:
2 - Flags: None affected.
โฌ
๏ธ SLA r8
Shift Left Arithmetically register r8 โ a 0 slides in at the bottom, everything marches left, the top bit exits into the carry ๐ช
โโ Flags โโ โโโโโโโโ r8 โโโโโโโ
โ C โโโโโ b7 โ ... โ b0 โโโ 0
โโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
- Cycles:
2 - Bytes:
2 - Flags:
Z= set if result is0,N=0,H=0,C= set according to result ๐ฆ
โฌ
๏ธ SLA [HL]
Shift Left Arithmetically the byte pointed to by HL. Same leftward march, memory edition ๐พ
โโ Flags โโ โโโโโโโ [HL] โโโโโโ
โ C โโโโโ b7 โ ... โ b0 โโโ 0
โโโโโโโโโโโ โโโโโโโโโโโโโโโโโโโ
- Cycles:
4 - Bytes:
2 - Flags: See โ
SLA r8โ
โก๏ธ SRA r8
Shift Right Arithmetically register r8 โ and heads up, bit 7 of r8 is unchanged, it just duplicates itself like a vibe check ๐ง
โโโโโโโ r8 โโโโโโโ โโ Flags โโ
โ b7 โ ... โ b0 โโโโโ C โ
โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโ
- Cycles:
2 - Bytes:
2 - Flags:
Z= set if result is0,N=0,H=0,C= set according to result ๐
โก๏ธ SRA [HL]
Shift Right Arithmetically the byte pointed to by HL โ and again, bit 7 of the byte pointed to by HL is unchanged ๐ซง
โโโโโโ [HL] โโโโโโ โโ Flags โโ
โ b7 โ ... โ b0 โโโโโ C โ
โโโโโโโโโโโโโโโโโโ โโโโโโโโโโโ
- Cycles:
4 - Bytes:
2 - Flags: See โ
SRA r8โ
โก๏ธ SRL r8
Shift Right Logically register r8 โ unlike SRA, a big fat 0 slides in at the top, so no sign-preserving behaviour here ๐ณ๏ธ
โโโโโโโโ r8 โโโโโโโ โโ Flags โโ
0 โโโ b7 โ ... โ b0 โโโโโ C โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโ
- Cycles:
2 - Bytes:
2 - Flags:
Z= set if result is0,N=0,H=0,C= set according to result ๐
โก๏ธ SRL [HL]
Shift Right Logically the byte pointed to by HL ๐ณ๏ธ
โโโโโโโ [HL] โโโโโโ โโ Flags โโ
0 โโโ b7 โ ... โ b0 โโโโโ C โ
โโโโโโโโโโโโโโโโโโโ โโโโโโโโโโโ
- Cycles:
4 - Bytes:
2 - Flags: See โ
SRL r8โ
๐ด STOP
Enter CPU very low power mode. Also used to switch between GBC double speed and normal speed CPU modes โ she does double duty, main character energy fr ๐
๐จ okay, listen: the exact behavior of this instruction is fragile, and it may interpret its second byte as a separate instruction (see the Pan Docs: https://gbdev.io/pandocs/Reducing_Power_Consumption.html#using-the-stop-instruction). That's whyrgbasm(1)allows explicitly specifying the second byte (STOP n8) to override the default of$00(aNOPinstruction). Don't just assume it's chill ๐
- Cycles:
- - Bytes:
2 - Flags: None affected.
โ SUB A,r8
Subtract the value in r8 from A. No carry shenanigans, just straight subtraction ๐ป
- Cycles:
1 - Bytes:
1 - Flags:
Z= set if result is0N=1H= set if borrow from bit 4C= set if borrow (i.e. ifr8> A)
โ SUB A,[HL]
Subtract the byte pointed to by HL from A ๐ป
- Cycles:
2 - Bytes:
1 - Flags: See โ
SUB A,r8โ
โ SUB A,n8
Subtract the value n8 from A ๐ป
- Cycles:
2 - Bytes:
2 - Flags: See โ
SUB A,r8โ
๐ SWAP r8
Swap the upper 4 bits in register r8 and the lower 4 ones. Nibble exchange, very demure, very mindful ๐
- Cycles:
2 - Bytes:
2 - Flags:
Z= set if result is0,N=0,H=0,C=0
๐ SWAP [HL]
Swap the upper 4 bits in the byte pointed by HL and the lower 4 ones ๐
- Cycles:
4 - Bytes:
2 - Flags: See โ
SWAP r8โ
๐ง XOR A,r8
Set A to the bitwise XOR between the value in r8 and A โก
- Cycles:
1 - Bytes:
1 - Flags:
Z= set if result is0,N=0,H=0,C=0
๐ง XOR A,[HL]
Set A to the bitwise XOR between the byte pointed to by HL and A โก
- Cycles:
2 - Bytes:
1 - Flags: See โ
XOR A,r8โ
๐ง XOR A,n8
Set A to the bitwise XOR between the value n8 and A โก
- Cycles:
2 - Bytes:
2 - Flags: See โ
XOR A,r8โ
๐ SEE ALSO ๐
๐ HISTORY ๐ฐ๏ธ
rgbasm(1) was originally written by Carsten Sรธrensen as part of the ASMotor package, and was later repackaged in RGBDS by Justin Lloyd. It is now maintained by a number of contributors at https://github.com/gbdev/rgbds โ go say hi to the maintainers, they're lowkey carrying the whole toolchain ๐ซถ๐
and that's the whole page, bestie!! ๐
โจ๐ shoutout to the Debian packagers for shipping this on September 22, 2026, and to GBZ80(7) herself for being the most iconic instruction set doc in the game. now go write some assembly, you absolute legend ๐๐ธ๐ฆ
๐ฆ where this page comes from
- arch rolling: rgbds 1.0.4-1 ยท MIT
- nixpkgs unstable: rgbds 1.0.4
- ๐ the page's license: MIT
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms