The length of the LD A, (C) instruction in the gameboy ~ Z80 processor

Hello, I am writing an emulator for Game Boy.

I use this link: Gameboy CPU instruction set (LR35902)

This document states that opcodes:

0xE2 LD (C),A 

and

 0xF2 LD A,(C) 

have a length of 2.

The Game Boy game processor manual says these instructions are as follows:

Put the value at the address $ FF00 + register C in A.

and

Put A at $ FF00 + register C.

I think it has a length of 1, because the operation code is self-contained, it does not need to use a different value for interpretation. If it has a length of 2, what is the purpose of the second byte?

+5
source share
1 answer

You are absolutely right. LD (C),A and LD A,(C) 1 byte long.

I even sent a letter to the person responsible (Pastraiser) asking for clarification (or if he could fix the site), but I did not receive a response.

Another thing that bothers me is that prefix CB counts as 1 byte and consumes 4 loops. And all extended instructions are considered 2 bytes long and consume 8 cycles (16 if they have access to (HL) ). It would be wiser for me to leave a space below prefix CB , so it’s clear that all extended instructions already include size and processing cycles for their prefix.

And the other thing that bothers me is the fact that the STOP length is 2. In fact, it is just one byte. Gameboy Classic has a hardware bug that causes a missing STOP command. So Nintendo started telling developers to add NOP always after STOP . So, to be 100% correct, I would consider STOP to be (1,4) instead of (2,4). This issue does not exist in Gameboy Color.

+6
source

Source: https://habr.com/ru/post/1261967/


All Articles