Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Gameboy Processor LR35902 Opcode 0x08 Meaning

Tags:

z80

gameboy

Could someone please explain what the opcode 0x08 does on the LR35902 processor. The mnemonic is LD (a16),SP.

I'm confused because the stack pointer is a 16-bit value but (a16) is an address to somewhere only capable of storing 8 bits (I think!). I could guess that the first 8 bits are placed into (a16) and the next are placed adjacent to those but I would like confirmation.

like image 244
user2674487 Avatar asked Mar 26 '16 20:03

user2674487


1 Answers

Yes, that opcode puts SP value at an address (a16). Here's what it will look like:

void MemoryWrite(uint16_t addr, uint8_t value);

MemoryWrite(a16, SP & 0xFF);
MemoryWrite(a16 + 1, (SP & 0xFF00) >> 8);

Because it's a little-endian processor you put least significant byte first.

like image 64
creker Avatar answered Oct 16 '22 02:10

creker