Hacker News new | ask | show | jobs
by nanochess 844 days ago
Automatic generation of code for Z80 is kind of hard because some operations are forced to use a few registers. For example, ADD only works with A or HL (and IX or IY), and the code generator requires register shuffling or using the stack for saving temporary values. My current approach is building a node tree for expressions, generating code by detecting common patterns, and if there isn't a pattern it goes the complicated but simple way. For example, for add: right expr. / push hl / left expr. / pop de / add hl,de