Hacker News new | ask | show | jobs
by ekimekim 18 days ago
A fast memcpy for the Game Boy makes use of pop instructions for the same purpose. Notably not push instructions, because pop is actually faster and you only have one stack pointer so you're better off using it for the source address (popping 16 bits into two registers at a time) than the dest.

You can also get savings by using the "store and increment HL" combined instruction, which saves time over "inc HL", but this requires you to move from the popped registers into A (this instruction only works with the A register). You can't pop directly into the A register because that pop variant, "pop AF", pops into A plus the hidden flags register which is not helpful.

So it looks like:

  pop DE
  ld A, D
  ld [HL+], A
  ld A, E
  ld [HL+], A