Close

Modifying the backend

A project log for Targeting SDCC to the 8080

Writing a code generator for the 8080 microprocessor for Small Device C Compiler (SDCC)

Ken YapKen Yap 09/23/2019 at 22:250 Comments

By this time you're getting impatient and wondering when I'm going to hack the backend, in particular the monster file gen.c.

Did I study the file carefully and make surgical changes? Hahaha, I wish. What I actually did was run the compiler across the selection of test programs in the regression directory, note any illegal code produced and change the generator to fix, and repeat. (It turns out that the regression directory isn't the real test suite but nonetheless as good a place to get my hands dirty as any.)

The changes fell into several categories:

Relative jumps JR had to be changed to absolute jumps JP. And DJNZ had to be done the long way. Straightforward.

Bit operations have to be done the long way by using the accumulator as an intermediate register. Fortunately the accumulator is regarded as volatile. Some bit tests, e.g on the top bit can be done with testing for negative instead of using AND.

Moves and compares that used the block instructions have to be done the long way.

Right shifts, as Alan Cox astutely noted years ago, have to be done the long way as the 8080 is terribly incapable in this area. All the remaining unhandled cases fell into this category. This deserves an entire log to itself, coming up.

Discussions