r/Compilers • u/This-Assumption-5924 • Oct 28 '26
I built a self-assembling x86-64 assembler from scratch
I've been working on AmmAsm, a handwritten x86-64 assembler, and recently achieved a milestone I wanted to document.
AmmAsm 1.0 was originally written in in C.
With AmmAsm 3.0.2, I managed to rewritte AmmAsm 1.0 code base to assembly x86-64, assemble it with verion 3.0.2, link, and run it again.
The repository now includes the original assembly source, test files, and execution evidence.
What makes this interesting to me is the connection between the versions: the newer assembler can process the assembly-language implementation of its own earliest version.
This isn't a claim that AmmAsm can compile itself from its current C source. Rather, it's a way to preserve and bring back an earlier stage of the project's development.
Repository: https://github.com/LinuxCoder13/AmmAsm
I'm curious how others here approach preserving old implementations and testing assemblers against real-world assembly code.
View all comments
2
u/[deleted] Oct 28 '26
So which was written first?! The aasm.asm file says it is a self-hosted of 'aasm.c', although I can't find any such file. So not a port of the C version shown in your link?
In any case, it's a little confusing, because the usual pattern is to write things in assembly then port to a HLL (if there is a reason to use assembly at all).
Was the aim to test a subtantial ASM program? One approach is to use a C compiler to generate smallish programs and work from there. Although I appreciate that the output from programs such as gcc can be daunting. You can however extract functions from it into their own file, tweak as needed, assemble that, and link against a test framework.
'Real-world assembly' meaning hand-written ASM, or can it be the output of a compiler? That's where most ASM code comes from.
I maintain a private HLL, which can generate ASM as an option. This uses my specific dialect of x64, and it is processed by my assembler, another project.
That can be tested on bigger programs which the compiler generates. It can sort of assemble itself, but it's rather contrived (here, 'mm' is my HLL compiler, and 'aa' is the assembler; aa.m is the lead source file of the assembler):
(The .asm file here is 45Kloc and represents the entire program. This assembler only needs to support the subset used by my HLL, or that can be written via inline assembly, so it can cut corners.)