XI XIRASM GitHub

Zig powered / Multi-ISA / Meta DSL

Build binaries like code.

XIRASM keeps ISA text readable, then adds a compile-time Meta language for multi-ISA generation, layout, token parsing, checked binary structures, and PE/COFF/ELF recipes.

3 backend families Meta compile-time DSL PE/COFF/ELF recipes
xirasm://source/main.xir
// natural ISA text stays natural
x86.use64();
origin(0x401000);

start:
    xor eax, eax

// compile-time Meta generates source
for i in list.of(0, 1, 2, 3) {
    isa(sym.join(
        "vaddps ymm", to_string(i),
        ", ymm", to_string(i),
        ", ymm", to_string(i + 1)
    ));
}

packed struct Header {
    magic: u16 = 0x5849,
    size: u16,
}

emit.bytes(pack(Header { size: 4 }));
01 Natural ISA text
02 One Meta language
03 Checked layout
04 Separated encoders
Language

A modern assembler language, not another pile of pseudo-directives.

XIRASM gives binary authors structured tools without turning every instruction into a function call.

Generate ISA text

Build register names, labels, and repeated hot paths with Meta code, then pass generated lines back through the normal backend encoder.

isa(sym.join("vaddps ymm", to_string(i)))

Parse tokens

Use token matching to write small DSLs, import tables, instruction descriptions, or source-like parsers inside assembly.

match.tokens("=mov dst:name =, src:tokens", line)

Check binary layouts

Define packed structs and unions, inspect size and offsets, then pack values directly into the output stream.

assert(sizeof(Header) == 4)

Patch final bytes

Finalizers run after layout is stable, so headers, sizes, checksums, and label-dependent fields can be backfilled deliberately.

store.u32(field, body_end - body_start)
Formats

Executable formats as readable recipes.

PE, COFF, and ELF support lives in include-driven format libraries. The common path uses facade helpers; raw record builders remain available when you need expert control.

PE32 / PE64 COFF objects ELF executables ELF objects ELF shared objects
PE64 EXE ELF64 EXE
import("format/pe64.inc");

pe64_exe(1);
pe64_section(".text", 0);
start:
    xor eax, eax
    ret
text_end:
pe64_end_section(0);
pe64_finish_text(0, start, start, text_end, pe_rx);
import("format/elf64.inc");

elf64_exe(1);
elf64_segment(".text");
start:
    mov eax, 60
    xor edi, edi
    syscall
text_end:
elf64_end_segment();
elf64_finish_load(0, start, start, elf_rx);
Architecture

Frontend language and ISA encoders stay separated.

Source
>
Meta expansion
>
Layout / fixups
>
xirasm-lib
>
Bytes
x86 / x86-64natural instruction text and encoder fixtures
RISC-VRV32/RV64 source and backend boundary
SPIR-Vbackend library family for module emission
Quick Start

Build it with Zig 0.17.

zig build
xirasm source.asm -o output.bin --target x86_64
xirasm init demo --target rv64
cd demo
xirasm build