Close

Choosing the instruction mnemonics

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 08/29/2019 at 02:000 Comments

As people know the Z80 chose to use a different set of mnemonics from the 8080. In my opinion the Z80 mnemonics are more logical. The 8080 mnemonics encoded the addressing mode in the instruction, so for example load immediate to accumulator was MVI A,nn but load immediate to HL was LXI HL,nnnn. For the Z80 mnemonics these are LD A,#nn and LD HL,#nnnn. There are other irregularities.

It wasn't hard to make a choice. The SDCC code generator for the Z80 generates the Z80 mnemonics, naturally. Even though the user normally doesn't look the assembler output, I had no desire to throw 8080 mnemonics into the mix. So Z80 mnemonics it was.

However I had to make assembler detect whenever an instruction not in the 8080 subset was used to catch code generation errors. So I hacked asz80 from asxxxx to accept an additional directive: .8080 which would make the assembler signal an error on such lines. I wasn't consistent in the method of detection. Some are caught at the syntax stage, by forbidding IX and IY, for example. The others are detected at the mnemonic decoding step, by forbidding EXX, for example. It isn't important, as long as an error is returned as this is something that "should not happen" and should be reported to the developer.

This was done in short order and you can find the hacked asz80, or rather sdasz80, since the SDCC developers have made several changes to the stock asxxxx distribution, in the GitHub repo.

Discussions