Z80 Assembly

I’m currently learning Z80 assembly (I’ve read the book once, but now I’m actually working through the exercises.) I have to say, it’s fun and a bit challenging at times. The challenge is partly learning the tools. I’m currently using z80pack. From that I’m using z80asm and z80sim. I’ve played a bit with the cpm2&3sim emulator that comes with it, but I currently only really need z80sim. z80asm can be a bit strange at time (or perhaps just more strict then the book.) For instance, LD C, (IX - 5) doesn’t work. Instead, I have to use LD C, (IX + -5)Not a huge deal at all, just wasn’t immediately apparent that I needed to add by the inverse to subtract from the register. As always, there’s a huge difference between reading and doing. It’s been very rewarding when I get some of these basic things working correctly. Basically I’ve got the hang of moving values around registers and memory, addition/subtraction, using the stack, and even played around a bit with the exchange instructions. It’s all very basic, but I’m trying to learn it really well so when I move on to ARM, SH, PowerPC, and perhaps even x86 assembly, I’ll have a really good base understanding and it will mainly be learning the new instruction set.

I’m actually kind of glad I got this book for free from the library (on the free book shelf.) Learning on an 8-bit processor has advantages and disadvantages. One of the greatest advantages of the Z80 is that there are quite a few good emulators for it. The great thing about z80sim is after your instructions have run it gives you a printout of what’s in the registers at HALT. You can then view the memory which you may have used for the stack, or just generally wrote to. You can then quickly clear the ram, and relatively easily clear the registers. Though, z80sim doesn’t seem to have an quick way to reset all registers to zero. So, until I find a better way (I could just quit and restart z80sim) I’m currently using this to reset the registers to 0 (with the exception of PC, which isn’t a big deal) ; clear the registers first
LD HL, 0
POP AF ; this makes sure AF is cleared
LD SP, HL ; ditto to the SP
LD BC, 0
LD DE, 0

; these have no swapped registers
LD IX, 0
LD IY, 0

; now clear the swapped registers
; we swap, then clear the registers again

LD HL, 0
LD BC, 0
LD DE, 0

HALTI hope I didn’t make some glaring mistake (or overlook an easier way.) Anyways, it seems to work quite well with z80simr clear.bin
f 0,ffff,0
Clears pretty much everything quite quickly. I may even dig into the code and add a reset command to do exactly this. It’s been a lot of fun honestly. I expect to be get through at another chapter tomorrow.

Long term goal after learning and understanding Z80 assembly: do some Game Gear and perhaps Gameboy homebrew (probably going to be very basic.)