Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles / Languages / C++

A Full-Featured Z80/8085 Assembler in C++

4.86/5 (8 votes)
14 May 2014CPOL1 min read 18.9K   564  
A full-featured Z80/8085 assembler in C++

Introduction

The task of assembling an assembly language source file into a machine readable output is at the basis of modern computing despite all the modern compilers and interpreted languages that are now built on top of the basic machine language. The Z80/8085 is a basic but complete instruction set that allows conceptual learning and thinking about the topics of assembler without going in depth into special processor features.

Coming soon: A Windows program with editor and dialog (requested in comments), basic simulator for CP/M.

Background

Familiarity with C++, assembly language, Z80/8085, Backus Naur Form (BNF), parsing, tokenizing, semantic and syntactic checking are preferable.

Using the Code

Using the class is as easy as passing in a readable assembler file for input with a writeable listing file and writeable hex format file for output (both in "w" text format).

C++
Assemble(inputFile, listFile, hexFile, fileName);  

Points of Interest

Assertions are used for internal errors where execution can continue safely while blind throws are placed in for any critical internal errors generally representing a bug in the code as they should be impossible to reach if the design is correct. Thrown errors for syntactic and semantic errors are used.

Cycle checking is implemented using a form of depth first search algorithm through any symbol table expressions.

The Intel hex format is used. See: http://www.keil.com/support/docs/1584.htm. Opcodes and clock cycle information can be found at http://www.z80.info/z80code.htm and http://www.z80.info/zip/z80-documented.pdf.

Expressions are used extensively and due to the recursive use have allowed a greater set of possibilities in the assembler input than would ordinarily be seen.

History

  • Initial version

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)