Romhacking.net
Romhacking => Programming => Topic started by: dACE on August 21, 2016, 09:15:12 am
-
Going through all ASM commands for GB to make a handy tool.
Why is there specific commands for things like:
ld a,a
ld b,b
...
The ld command does not set any flags right? So what other reason is there to include these commands?
/dACE
-
I can't think of any practical use.
They probably only exist for hardware reasons. If you look at the opcode matrix, you'll see a pattern in how register parameters correspond to certain columns:
http://www.pastraiser.com/cpu/gameboy/gameboy_opcodes.html
It would have been harder (and probably more expensive) to make exceptions to break that pattern.
So since $xF LD's from A
and the 2nd half of $7x LD's to A
That makes $7F LD A,A, even though that isn't a practical opcode.
-
Thanks Disch,
I kinda suspected what you posted - but thought it best to ask around just in case.
/dACE
-
I don't know about GB/GBC but similar such things on other systems make for a reasonable NOP.
-
I know squat about neither Z80 nor 8080 programming, and even less about Gameboy, but wouldn't this set the program status flag to the A register, for example set the zero flag is A is zero, or the negative flag if A is negative ?
-
LD on the z80 doesn't modify flags like LDA does on the 6502. So LD A,A is effectively a NOP
But it also has a proper NOP instruction. So *shrug*
-
I remember reading somewhere that this was done either to help the programmer count CPU cycles, or it was because of a bug in the CPU (using a NOP right after another certain statement). I think it was in the GBC Reference Guide posted here in RHnet.