🏠 Home Page


GBZ80

The Game Boy uses a processor called the Sharp LR35902 which has many similarities to the Intel 8080 and Zilog Z80 processors. On the DMG Game Boy, the processor operates at about 4.19MHz, but the CGB (Game Boy Color) console allows for a double speed mode with allows the processor to run at about 8.38MHz.

GBZ80 Instructions

GBZ80 Status Flags (F)

GBZ80 Number Bases

GBZ80 Opcode Placeholder Values

ADC - Add With Cary

Adds target value and Carry Flag (CF) (1 if set or 0 if clear) to source and stores the result in source

Status Flags (F) After Use:

ADC A,r8

ADC A,[HL]

ADC A,u8

ADD (8-bit) - Add

Adds the A register value and target value together and stores the result in the A register

Status Flags (F) After Use:

ADD A,r8

ADD A,[HL]

ADD A,u8

ADD (16-bit) - Add

Adds source value and target value together and stores the result in source

Status Flags (F) After Use:

ADD HL,r16

ADD HL,SP

AND - Logical AND

Performs a logical AND between source value and target value and stores the result in source

Status Flags (F) After Use:

AND A,r8

AND A,[HL]

AND A,u8

BIT - Test Bit

Test specified bit of target value

Status Flags (F) After Use:

BIT u3,r8

BIT u3,[HL]

CALL - Call Address

Advance Program Counter (PC) to next instruction, then decrement the Stack Pointer (SP), then copy the High byte of the Program Counter (PC) into the address pointed to by the Stack Pointer (SP), then decrement the Stack Pointer (SP) a second time, then copy the Low byte of the Program Counter (PC) into the address pointed to by the Stack Pointer (SP), then set the Program Counter (PC) to target address

Status Flags (F) After Use:

CALL u16

CALL cc,u16

CCF - Complement Carry Flag

Performs a logical NOT of the Carry Flag (CF) and sets the Carry Flag (CF) to the result

Status Flags (F) After Use:

CCF

CP - Compare A Register

Subtract target value from A register, setting status flags accordingly, but does not store the result

Status Flags (F) After Use:

CP A,r8

CP A,[HL]

CP A,u8

CPL - Complement A Register

Performs a logical NOT of the A register and sets the A register to the result

Status Flags (F) After Use:

CPL

DAA - Decimal Adjust A Register

Converts the A register value to Binary-Coded Decimal (BCD). In essence, if the Negative Flag (NF) was set at the start of this instruction, an adjustment is made by subtracting 6 from each nibble (left and right 4-bit halves of a byte) that is larger than 9, otherwise if the Negative Flag (NF) was clear at the start of this instruction, an adjustment is made by adding 6 to each nibble that is larger than 9.

Status Flags (F) After Use:

DAA

DEC (8-bit) - Decrement Value

Decrement source value by 1 and store the result in source

Status Flags (F) After Use:

DEC r8

DEC [HL]

DEC (16-bit) - Decrement Value

Decrement source value by 1 and store the result in source

Status Flags (F) After Use:

DEC r16

DEC SP

DI - Disable Interrupts

Clears Interrupt Master Enable (IME)

Status Flags (F) After Use:

DI

EI - Enable Interrupts

Sets Interrupt Master Enable (IME) after the next instruction

Status Flags (F) After Use:

EI

HALT - Enter CPU Low-Power Mode

Halt CPU, entering low-power consumption mode until interrupt occurs

Status Flags (F) After Use:

HALT

INC (8-bit) - Increment Value

Increment source value by 1 and store the result in source

Status Flags (F) After Use:

INC r8

INC [HL]

INC (16-bit) - Increment Value

Increment source value by 1 and store the result in source

Status Flags (F) After Use:

INC r8

INC SP

JP - Jump to Address

Set Program Counter (PC) to target address

Status Flags (F) After Use:

JP u16

JP cc,u16

JP [HL]

JR - Jump Relative

Relative jump to target address. While the GBZ80 assembly code uses a 16-bit little-endian address, the machine code uses a signed 8-bit number for the target value (-128 to 127 bytes away from the address following the JR instruction). The target address MUST be within -128 to 127 bytes away from the address following the JR instruction.

Status Flags (F) After Use:

JR u16

JP cc,u16

LD (8-bit) - Load Value

Copy value from target value and store it into source

Status Flags (F) After Use:

LD r8,r8

LD r8,u8

LD [HL],r8

LD [HL],u8

LD r8,[HL]

LD [r16],A

LD [u16],A

LD A,[r16]

LD A,[u16]

LD [HL+],A

LD [HL-],A

LD A,[HL+]

LD A,[HL-]

LD (16-bit) - Load Value

Copy value from target value and store it into source

Status Flags (F) After Use:

LD r16,u16

LD SP,u16

LD [u16],SP

LD SP,[HL]

LD (Misc. 1) - Load Value

Copy the Low byte value of the Stack Pointer (SP) and store it into source address, then copy the High byte of the Stack Pointer (SP) and store it into source address + 1

Status Flags (F) After Use:

LD [u16],SP

LD (Misc. 2) - Load Value

Copy the value of the Stack Pointer, add a specified signed byte to it, and store the result into the HL combined register

Status Flags (F) After Use:

LD HL,SP+s8

LDH - Load With Last Page

Copy value from target value and store it into source

Status Flags (F) After Use:

LDH [u8],A

LDH [C],A

LDH A,[u8]

LDH A,[C]

NOP - No Operation

No operation occurs (Good way to use up CPU cycles)

Status Flags (F) After Use:

NOP

OR - Logical OR

Performs a logical OR between source value and target value and stores the result in source

Status Flags (F) After Use:

OR A,r8

OR A,[HL]

OR A,u8

POP - Pop Value From Stack

Copy the value at the address pointed to by the Stack Pointer (SP) into the Low byte of the combined-register, then increment the Stack Pointer (SP), then copy the value at the address pointed to by the Stack Pointer (SP) into the High byte of the combined-register, then increment the Stack Pointer (SP) a second time

Status Flags (F) After Use:

POP r16

POP (AF) - Pop Value From Stack

Copy the value at the address pointed to by the Stack Pointer (SP) into Status Flags (F), then increment the Stack Pointer (SP), then copy the value at the address pointed to by the Stack Pointer (SP) into the A register, then increment the Stack Pointer (SP) a second time

Status Flags (F) After Use:

POP AF

PUSH - Push Value to Stack

Decrement the Stack Pointer (SP), then copy the High byte of the combined-register value into the address pointed to by the Stack Pointer (SP), then decrement the Stack Pointer (SP) a second time, then copy the Low byte of the combined-register value into the address pointed to by the Stack Pointer (SP)

Status Flags (F) After Use:

PUSH r16

PUSH AF

RES - Clear Bit

Clear (set value to 0) specified bit of target value

Status Flags (F) After Use:

RES u3,r8

RES u3,[HL]

RET - Return From Subroutine

Copy the value at the address pointed to by the Stack Pointer (SP) into the Low byte of the Program Counter (PC), then increment the Stack Pointer (SP), then copy the value at the address pointed to by the Stack Pointer (SP) into the High byte of the Program Counter (PC), then increment the Stack Pointer (SP) a second time

Status Flags (F) After Use:

RET

RET cc

RETI - Return From Subroutine Enable Interrupts

Copy the value at the address pointed to by the Stack Pointer (SP) into the Low byte of the Program Counter (PC), then increment the Stack Pointer (SP), then copy the value at the address pointed to by the Stack Pointer (SP) into the High byte of the Program Counter (PC), then increment the Stack Pointer (SP) a second time, then sets Interrupt Master Enable (IME)

Status Flags (F) After Use:

RETI

RL - Rotate Left Through Carry Flag

Shift every bit of source left 1, setting bit 0 of the result to the value of the Carry Flag (CF) (1 if set or 0 if clear) and then setting the Carry Flag (CF) to bit 7 of the source, then store the result in source

Status Flags (F) After Use:

RL r8

RL [HL]

RLA - Rotate A Register Left Through Carry Flag

Shift every bit of the A register left 1, setting bit 0 of the result to the value of the Carry Flag (CF) (1 if set or 0 if clear) and then setting the Carry Flag (CF) to bit 7 of the A register, then store the result in the A register

Status Flags (F) After Use:

RLA

RLC - Rotate Left

Shift every bit of source left 1, setting bit 0 of the result to bit 7 of the source and then setting the Carry Flag (CF) to the bit 7 of the source, then store the result in source

Status Flags (F) After Use:

RLC r8

RLC [HL]

RLCA - Rotate A Register Left

Shift every bit of the A register left 1, setting bit 0 of the result to bit 7 of the A register and then setting the Carry Flag (CF) to the bit 7 of the A register, then store the result in the A register

Status Flags (F) After Use:

RLCA

RR - Rotate Right Through Carry Flag

Shift every bit of source right 1, setting bit 7 of the result to the value of the Carry Flag (CF) (1 if set or 0 if clear) and then setting the Carry Flag (CF) to bit 0 of the source, then store the result in source

Status Flags (F) After Use:

RR r8

RR [HL]

RRA - Rotate A Register Right Through Carry Flag

Shift every bit of the A register right 1, setting bit 7 of the result to the value of the Carry Flag (CF) (1 if set or 0 if clear) and then setting the Carry Flag (CF) to bit 0 of the A register, then store the result in the A register

Status Flags (F) After Use:

RRA

RRC - Rotate Right

Shift every bit of source right 1, setting bit 7 of the result to bit 0 of the source and then setting the Carry Flag (CF) to the bit 0 of the source, then store the result in source

Status Flags (F) After Use:

RRC r8

RRC [HL]

RRCA - Rotate A Register Right

Shift every bit of the A register right 1, setting bit 7 of the result to bit 0 of the A register and then setting the Carry Flag (CF) to the bit 0 of the A register, then store the result in the A register

Status Flags (F) After Use:

RRCA

RST - Reset Vector

Advance Program Counter (PC) to next instruction, then decrement the Stack Pointer (SP), then copy the High byte of the Program Counter (PC) into the address pointed to by the Stack Pointer (SP), then decrement the Stack Pointer (SP) a second time, then copy the Low byte of the Program Counter (PC) into the address pointed to by the Stack Pointer (SP), then set the Program Counter (PC) to [$0000 + target reset vector]

Status Flags (F) After Use:

RST vec

SBC - Subtract With Carry

Subtracts target value and Carry Flag (CF) (1 if set or 0 if clear) from the A register and stores the result in the A register

Status Flags (F) After Use:

SBC A,r8

SBC A,[HL]

SBC A,u8

SCF - Set Carry Flag

Sets the Carry Flag (CF)

Status Flags (F) After Use:

SCF

SET - Set Bit

Set (set value to 1) specified bit of target value

Status Flags (F) After Use:

SET u3,r8

SET u3,[HL]

SLA - Arithmetic Shift Left

Shift every bit of source left 1, setting bit 0 of the result to 0 and then setting the Carry Flag (CF) to the bit 7 of the source, then store the result in source

Status Flags (F) After Use:

SLA r8

SLA [HL]

SRA - Arithmetic Shift Right

Shift every bit of source right 1, setting bit 7 of the result to bit 7 of the source and then setting the Carry Flag (CF) to the bit 0 of the source, then store the result in source

Status Flags (F) After Use:

SRA r8

SRA [HL]

SRL - Logical Shift Right

Shift every bit of source right 1, setting bit 7 of the result to 0 and then setting the Carry Flag (CF) to the bit 0 of the source, then store the result in source

Status Flags (F) After Use:

SRL r8

SRL [HL]

STOP - Enter CPU Very Low-Power Mode

Halts CPU, entering very low-power consumption mode until any of bits 0-3 of P1/JOY [$FF00] which means the P1 register should be enabled by setting bit 4 or 5 of P1/JOY [$FF00] to 1 before executing a STOP command if the intention is to put the CPU in very low-power mode. IT IS RECOMMENDED NOT TO USE THIS INSTRUCTION FOR ITS HALTING PURPOSE, AS IT BEHAVES UNEXPECTEDLY ON GAME BOY HARDWARE. This instruction is also be used to toggle double speed mode on the CGB by setting bit 0 of KEY1 [$FF4D] to 1 before executing the STOP instruction.

Status Flags (F) After Use:

STOP $00

SUB - Subtract

Subtracts target value from the A register and stores the result in the A register

Status Flags (F) After Use:

SUB A,r8

SUB A,[HL]

SUB A,u8

SWAP - Swap Nibbles

Swap each nibble (left and right 4-bit halves of a byte) of source value and store the result in source

Status Flags (F) After Use:

SWAP r8

SWAP [HL]

XOR - Logical XOR (Exclusive OR)

Performs a logical XOR (Exclusive OR) between source value and target value and stores the result in source

Status Flags (F) After Use:

XOR A,r8

XOR A,[HL]

XOR A,u8

GBZ80 Opcodes Table

       0    1    2    3    4    5    6    7    8    9    A    B    C    D    E    F
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0x0_ |NOP | LD | LD |INC |INC |DEC | LD |RCLA| LD |ADD | LD |DEC |INC |DEC | LD |RRCA|
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0x1_ |STOP| LD | LD |INC |INC |DEC | LD |RLA | JR |ADD | LD |DEC |INC |DEC | LD |RRA |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0x2_ | JR | LD | LD |INC |INC |DEC | LD |DAA | JR |ADD | LD |DEC |INC |DEC | LD |CPL |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0x3_ | JR | LD | LD |INC |INC |DEC | LD |SCF | JR |ADD | LD |DEC |INC |DEC | LD |CCF |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0x4_ | LD | LD | LD | LD | LD | LD | LD | LD | LD | LD | LD | LD | LD | LD | LD | LD |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0x5_ | LD | LD | LD | LD | LD | LD | LD | LD | LD | LD | LD | LD | LD | LD | LD | LD |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0x6_ | LD | LD | LD | LD | LD | LD | LD | LD | LD | LD | LD | LD | LD | LD | LD | LD |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0x7_ | LD | LD | LD | LD | LD | LD |HALT| LD | LD | LD | LD | LD | LD | LD | LD | LD |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0x8_ |ADD |ADD |ADD |ADD |ADD |ADD |ADD |ADD |ADC |ADC |ADC |ADC |ADC |ADC |ADC |ADC |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0x9_ |SUB |SUB |SUB |SUB |SUB |SUB |SUB |SUB |SBC |SBC |SBC |SBC |SBC |SBC |SBC |SBC |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0xA_ |AND |AND |AND |AND |AND |AND |AND |AND |XOR |XOR |XOR |XOR |XOR |XOR |XOR |XOR |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0xB_ | OR | OR | OR | OR | OR | OR | OR | OR | CP | CP | CP | CP | CP | CP | CP | CP |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0xC_ |RET |POP | JP | JP |CALL|PUSH|ADD |RST |RET |RET | JP |0xCB|CALL|CALL|ADC |RST |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0xD_ |RET |POP | JP |    |CALL|PUSH|SUB |RST |RET |RETI| JP |    |CALL|    |SBC |RST |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0xE_ |LDH |POP | LD |    |    |PUSH|AND |RST |ADD | JP | LD |    |    |    |XOR |RST |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0xF_ |LDH |POP | LD | DI |    |PUSH| OR |RST | LD | LD | LD | EI |    |    | CP |RST |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+

Prefix 0xCB
       0    1    2    3    4    5    6    7    8    9    A    B    C    D    E    F
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0x0_ |RLC |RLC |RLC |RLC |RLC |RLC |RLC |RLC |RRC |RRC |RRC |RRC |RRC |RRC |RRC |RRC |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0x1_ | RL | RL | RL | RL | RL | RL | RL | RL | RR | RR | RR | RR | RR | RR | RR | RR |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0x2_ |SLA |SLA |SLA |SLA |SLA |SLA |SLA |SLA |SRA |SRA |SRA |SRA |SRA |SRA |SRA |SRA |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0x3_ |SWAP|SWAP|SWAP|SWAP|SWAP|SWAP|SWAP|SWAP|SRL |SRL |SRL |SRL |SRL |SRL |SRL |SRL |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0x4_ |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0x5_ |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0x6_ |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0x7_ |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |BIT |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0x8_ |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0x9_ |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0xA_ |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0xB_ |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |RES |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0xC_ |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0xD_ |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0xE_ |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+
0xF_ |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |SET |
     +----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+----+

Incoming Wiki Links

{index}