Glass Z80 assembler

Copyright 2013 Laurens Holst

Project information

Glass is a cross-assembler for the Z80 processor written in Java 8. Its core principles are to be open source, cross-platform, and to provide a standard Z80 syntax infused with modern language features.

It presents a flexible language for Z80 object code generation by building an abstract syntax tree with strong scoping rules, rather than using the traditional multi-pass architecture with separate preprocessor and mnemonic translation. This allows the user to write powerful expressions, use macros as type definitions, etc. Future developments aim to bring more modern programming concepts to the Z80 assembly programming realm.

Because the binary is a jar which runs on the Java virtual machine, it can be included in a project easily without requiring the user to acquire a separate binary build for their operating system.

Downloads

See the release notes for what’s new.

Usage instructions

To run Glass from the command line, use the following command.

java -jar glass.jar [OPTION] SOURCE [OBJECT] [SYMBOL]

Source specifies the source file, object the output file, and symbol a text file which will hold a list of symbols and their addresses in the output.

Supported options:

-I include_path

Note that Java 8 must be installed to run Glass. To check your Java version, invoke the `java -version` command.

Syntax

The assembler syntax follows common style.

Lines are composed as follows:

label: mnemonic arguments ;comment

Note that the white space before the mnemonic is significant; otherwise, it will be interpreted as a label.

All identifiers are case-sensitive. Mnemonics of built-in instructions, directives, registers, flags and annotations are recognised in lowercase and uppercase, but can not be mixed case.

Labels

Labels and other identifiers follow the following grammar:

identifier = id_start_char id_char*
id_start_char = [a-z] | [A-Z] | _ | . | ? | @
id_char = id_start_char | [0-9] | ' | $

The colon after a label is optional. If a label has no colon, it can not have any leading white space, it must start at column 0.

Instructions

Standard z80 instruction syntax is used:

ld a,(ix + 10)

Parentheses are used to indicate indirection.

Directives

Literals

Strings support the following escape sequences:

Numeric escape sequences are not supported. In stead, you can insert them using the comma operator: "abc", 0FFH, "def".

The character set used to read files is ISO-8859-1, this maps the file’s bytes 1:1 to the Unicode code points used internally so the object code output matches the input file bytes verbatim.

The assembler uses 32-bit integer math internally. When a 8-bit or 16-bit value is generated, the excessive bits are usually truncated. Except for addresses, used in jumps, calls and indirect loads, they generate an error. Index and relative jump offsets are also checked to be in their allowed range.

Operators

Logical operators use integers to represent true / false values. 0 means false, any other value means true. They return -1 for true values.

Logical and / or apply short-circuit evaluation and evaluate to the last evaluated value, so they can also be used similar to a ternary operator.

Expressions can span multiple lines when they’re incomplete at the line ends.

Operator precedence:

  1. .
  2. unary + - ~ !
  3. * / %
  4. + -
  5. << >>
  6. < <= > >=
  7. = !=
  8. &
  9. ^
  10. |
  11. &&
  12. ||
  13. ?:
  14. ,

Development information

Glass is free and open source software. If you want to contribute to the project you are very welcome to. Please contact me at any one of the places mentioned in the project information section.

You are also free to re-use code for your own projects, provided you abide by the license terms.

Glass is written in Java 8. To check your Java version, invoke the java -version command. The project can be built using Maven by invoking the following command on the command line:

mvn verify

The jar binary will be output to the target directory.

Release notes

For the complete list of changes please refer to the revision history.