Converting 8080 to Z80 Assembly


Introduction to Converting 8080 to Z80 Assembly

In this section, we’ll discuss Converting 8080 to Z80 Assembly. In most cases, you should be able to run an 8080 assembler on 8080 assembly code. The binary should run on the Z80 processor. If you need to convert small portions of 8080 assembly to use in a Z80 project though, this is fairly easy to do. There are even programs and libraries to help with this conversion. You will find a discussion on this topic at this link.

Basically, I prefer the manual conversion method, though for small pieces of code. This helps me to better understand the differences between the two sets of mnemonics.

In this case, we’ll simply convert a program to ring the console bell. This program is from page 52 of the book “Mastering CP/M” by Alan Miller. I’ve modified the 8080 code slightly.

; RING A BELL (8080 Code)

BEL:        EQU     7
BDOS:       EQU     0005H
TYPEF:      EQU     2

            ORG     0100H
START:      LXI     SP,0100H
            MVI     C,TYPEF
            MVI     E,BEL
            CALL    BDOS
            JMP     0
            END
            

To convert this small program, we’ll open two links. We’ll use the 8080 Opcode table, and the Z80 Opcode table.

My Procedure for Converting 8080 to Z80 Assembly

For the most part, our EQU statements are fine. You might have to modify them slightly depending on the compiler that you are using. For example, the z80asm compiler for linux needs a “:” after each label. This even applies to the labels for the EQU statements.

As you can see, the first command that we need to convert to Z80 is “LXI SP,0100H”. Let’s look this up on the 8080 Table from the link above. What we want to get is the hex code for this command. For the most part, you can simply perform a FIND in your web browser. Search for the mnemonic, and it’s first operand.

The hex code is 31h. Now, let’s look up this code on the Z80 opcode page from the link above.

As you can see, the command will be “LD SP,nn”, which in this case will be “LD SP,0100H”.

After doing this for each opcode, we start to get the hang of how to convert the instructions. They are not all quite that straight-forward. This simple program gives us some good practice of how to look up the mnemonics though.

We will end up with a program that looks similar to this.

; RING A BELL (Z80 Code)

BEL:        EQU     7
BDOS:       EQU     0005H
TYPEF:      EQU     2

            ORG     0100H
START:      LD      SP,0100H
            LD      C,TYPEF
            LD      E,BEL
            CALL    BDOS
            JP      0
            END
            

Finally, we’ll save this file as “BELL.Z80”.

Compiling the Z80 Code

At this point, you can compile (assemble) the code. I already have z80asm on my z80 machine that I downloaded from retroarchive. I’m going to send this file to the Z80 machine so I can run the assembler.

The assembler creates an executable COM file. To run this file, we’ll simply type “BELL” at the command prompt.

You should hear the bell ring on your console (assuming the volume is turned up, and your terminal program supports the bell)!

Summary for Converting 8080 to Z80 Assembly

In short, you can assemble most 8080 programs with an 8080 assembler, and they will run fine on a z80 machine. The opcodes are the same. If you wish to use parts of 8080 code in a z80 project, though, you probably need to convert the commands. For legal reasons, they had to have different mnemonics even though the opcodes are the same. You can’t always go from Z80 to 8080 as easily though. This is because the Z80 has additional commands that are not directly backward compatible to the 8080 processor.

For more information, visit the Vintage Computer Category Page!

— Ricky Bryce

Leave a comment

Your email address will not be published. Required fields are marked *