Sunday, 16 March 2014

Computus 3

It's been a few years since my last look at calculating the date of Easter Sunday using only Z80 machine code, but I thought I'd finally re-visit it. In particular, I wanted to look in detail at Al Petrofsky's awesome optimizations of my lame attempts.



If you want a master-class in optimizing integer calculations on archaic CPUs (and who doesn't?) look no further than Al's solution. It's the product of deep understanding of:
  • The Z80 instruction set,
  • Integer multiplication-by-constants,
  • Integer division-by-constants,
  • Modulo arithmetic, and
  • Easter computus.
At only two hundred or so opcodes, and no branches, it's a beautiful distillation.