sarnau / Z80DisAssembler

I created this small disassembler for a Z80 cpu in one afternoon. It is a commandline tool.
17 stars 5 forks source link

Z80DisAssembler

The Z80 CPU was widely used in the 80s in many home computer. Even today it is often used as a cheap embedded CPU. If you need more information can get one of the following books:

Z80 Disassembler

I created this small disassembler for a Z80 cpu at one afternoon. It is a commandline tool. The size of the ROM and entry points have to be coded directly in the sourcecode.

Every ANSI C++ compiler should compile this program. It only uses some ANSI C functions (look into main()). Current program versions can be compiled successfully with gcc and clang w/o warnings.

The program has two parts:

The subroutine OpcodeLen() returns the size of one opcode in bytes. It is called while parsing and while disassembling.

The disassembler recognizes some hidden opcodes.

If a routine wanted an "address" to the Z80 code, it is in fact an offset to the array of code. No pointers! Longs are not necessary for a Z80, because the standard Z80 only supports 64k.

This program is freeware. It is not allowed to be used as a base for a commercial product!

Z80 Assembler

I created the assembler for the Z80 a few days later to compile the changes code from the disassembler into an EPROM image and build a new firmware for my aquarium computer. I needed almost two days for the assembler, this means: commandline only... If you want to change the filename of the sourcefile, you have to change main().

This small assembler has some nice gadgets: it is a quite fast tokenizing single-pass assembler with backpatching. It knows all official Z80 opcodes and some undocumented opcodes (mainly with IX and IY). The Z80 syntax is documented in the Zilog documentation.

The assembler allows mathematical expressions in operands: +, -, *, /, % (modulo), & (and), | (or), ! (not), ^ (xor), << (shift left) and >> (shift right). Brackets are also available. The expression parser is located in z80_calc.c. Numbers can be postpended by a D, H or B for decimal, hexadecimal and binary numbers. Numbers prepended by a $ are recognized as hex.

The assembler also knows the most commend pseudo opcodes (look into the sourcefile 'z80_tokenize.cp'):

The Sourcecode