
Show HN: Torque – A lightweight meta-assembler for any processor by benbridle
Torque is a lightweight meta-assembler that provides the tools necessary to write programs for any processor architecture.

For a quick overview of the language, either read the language overview section of the manual, see this example of a completed program, or skim one of the following hands-on tutorials:
For a demonstration of how to write high-level optimising macros in Torque, see:
Background
Existing assemblers for embedded processors suffer from a number of issues. Assemblers tend to be poorly documented, provide languages that are clunky and verbose, be bloated and difficult to operate, and work only on one operating system. Development of C compilers is often a higher priority than the development of good assemblers.
Instead of learning a new assembler for every embedded processor, it would be preferrable to instead
14 Comments
sitkack
Super fun site!
Did you get inspiration from other assemblers or macro processors?
You have it running on a TRS-80, how does that work? I had no idea Rust could target a TRS-80.
I am getting hints of Forth, Lisp and TCL.
How would you go about laying out structs in memory?
I am sure you considered an internal DSL, what caused you go with something stand alone?
Any thoughts on adding a constraint solver, like Z3 and allowing end users to set constraints on things like the size of a jump.
I could see taking this an growing it into a compiler by making macro(macro(macros txt)))
Is there an internal IR?
Projects for inspiration
https://github.com/mattbierner/Template-Assembly
Specifying representations of machine instructions
https://dl.acm.org/doi/pdf/10.1145/256167.256225
https://www.semanticscholar.org/paper/Specifying-representat…
Typed Assembly Language (TAL)
https://www.cs.cornell.edu/talc/
And you haven't come across it, you are in for a treat https://en.wikipedia.org/wiki/META_II has spawned a whole trove of clones
https://en.wikipedia.org/wiki/OMeta
https://github.com/DalekBaldwin/clometa
zadkey
Excellent work man!
I know some low level guys who would really appreciate this.
anonzzzies
Well done! I write quite a bit of z80 for msx and this seems a nice addition.
curtisszmania
[dead]
2ton_jeff
Very cool and I like the idea of a "meta-assembler." The most-recent version of flatassembler (fasm 2) is built with fasmg which is also a "meta-assembler" of sorts, in that it also doesn't directly support a specific instruction set and instead is a very powerful macro assembler. I'm keen to check out functionality overlaps between the two implementations.
https://board.flatassembler.net/topic.php?t=19389
https://flatassembler.net/download.php
angelmm
Any time I read about Z80, my mind wants to try to run something on a GameBoy emulator.
Pretty cool project!
eterps
Nice!
Would be interesting to target the RISC CPU of https://www.projectoberon.net with it.
userbinator
Reminds me of TDASM from the turn of the century: https://web.archive.org/web/20230906054935/http://www.pengui…
I remember there were a few other meta-assemblers I came across in the 80s-90s, so this is definitely not "unchartered territory", but it's good to see another one show up.
Of course, in the other direction there are meta-disassemblers used for analysis in tools like Ghidra.
kunley
Need to address this point:
"Assemblers tend to be poorly documented"
I wish everything in programming was as good documented as assemblers and ISAs.
bjackman
At first I thought it was useless: "but each ISA will still end up having different effective syntax because the underlying macro systems will not be designed the same".
But then I reread it and realised I was not paying attention to the usecase. It's about making it easy to write assemblers. So this isn't for your Arms and RISC-Vs it's for your random niche microcontrollers where the vendor-provided toolchain kinda sucks.
Seems cool!
I've experienced a couple of under-documented assemblers in my time. In neither case did this turn out to be that much of a problem in practice, but I guess I just don't write that much assembly.
MathMonkeyMan
I'm reminded of a 2016 [talk][1] where Rob Pike describes the common-denominator assembly language that the Go compiler generates. Then that assembly is translated into machine-specific code via table lookups. See the 11 minute mark.
[1]: https://www.youtube.com/watch?v=KINIAgRpkDA
roetlich
This looks very cool, maybe I'll try this for risc-v if I have some time. I guess you could also use this to write RAW images, or other binary data.
zzo38computer
Is there any support for non-Unicode text? Is there any support for octal numbers? These things should be corrected, hopefully.
Also, some of the links in the table of contents of the documentation does not seems to work.
vanderZwan
I shared Torque elsewhere and people asked what license it has