1
0
Fork 0
A simple bootstrapping hexadecimal assembler
  • HexadecimalAssemblyInstructions 64.1%
  • C 19.6%
  • Shell 8.8%
  • Assembly 7.5%
Find a file
2026-07-26 16:47:55 +02:00
examples setup 2026-07-26 16:47:55 +02:00
ref setup 2026-07-26 16:47:55 +02:00
.editorconfig setup 2026-07-26 16:47:55 +02:00
.gitattributes setup 2026-07-26 16:47:55 +02:00
.nvim.lua setup 2026-07-26 16:47:55 +02:00
License.md setup 2026-07-26 16:47:55 +02:00
Readme.md setup 2026-07-26 16:47:55 +02:00

HXA - Hexadecimal Assembler

This is a simple bootstrapping assembler, using its own custom syntax.

TODO

  1. Update Reference Implementation to support Labels
  2. Write bootstrapped implementation

Usage

HXA takes the input data to assemble via the stdin and returns the final result via stdout.

Exit Codes

Code When
2 Invalid data
3 Nibble left
4 Invalid label name
5 Duplicate label name
6 Unclosed label
7 Reference of undefined label
8 Invalid reference endian format
9 Reference address too big

Hexadecimal Assembly Instructions Specification

Hexadecimal assembly instructions, or short HXAI, is a simple format for defining bytes to assemble together.

Files

It is recommended to use the .hxai file extension for HXAI

Syntax

Comments

For any line all content after and including a ; will be ignored.

White Space

All spaces, and \n are ignored.

Data

Outside comments and supported whitespaces, anything else is seen as data.

Data is only allowed to use the characters [0-9A-F]. Data is always read, left to right, 2 characters at a time. 2 characters together represent a byte. Whitespaces are not allowed between both characters of a byte.

If only 1 char is left, and thus no full byte can be constructed, it is also invalid data.

Labels

HXAI supports labels. The label syntax is delimited by [ and ]. Comments are not allowed inside [...].

Nesting

Labels may not be nested. A [ may not appear inside an open [...], An unclosed [ followed by another [ is invalid.

Definition

A label is defined with the syntax [NAME|DATA]. NAME may only contain the characters [a-z] and -. DATA must parse as normal Data, and follows the same restrictions. The DATA of a definition is emitted in place, as if written without the surrounding label syntax. Each NAME must be unique and is immutable, redefining a NAME is invalid.

Reference

A label is referenced with the syntax [NAME>E_SIZE]. This emits the offset of the referenced label's left-most DATA byte. NAME must refer to a label defined somewhere in the input and thus can be referenced, before it is defined. E_SIZE sets both the width and byte order of the emitted offset. It is a decimal number of bytes, prefixed with l for little-endian or b for big-endian. The decimal number has to be positive integer. The offset must fit within E_SIZE bytes, otherwise it is invalid. If the offset needs fewer bytes than E_SIZE, it is padded with 00 bytes to fill the width.

Offsets

Label may alternatively be written in the format [NAME>E_SIZE+OFFSET]. The OFFSET has to be valid data. It will be added to the calculated reference. The OFFSET has to be written in big-endian format. The final calculated size, has to still fit into the defined E_SIZE.