In the search for faster interpreters, Just-In-Time compilation is often a useful tool. This compiler extension attempts to make the writing of such programs easier and faster.
At its core, dynasm-rs is an assembler compiler. It reads assembly templates which it then compiles into code that when executed will result in the proper machine code being emitted.
Dynasm is split up into two parts. The first is the compiler extension that performs the translation of assembly templates into rust code, the second part is a small runtime that handles the generation of the wanted machine code.
For now dynasm-rs only supports the x86 and x64 instruction set architectures.
Dynasm-rs is inspired by the LuaJIT DynASM project for C and C++.
The documentation of dynasm-rs is split up into several parts. To get started, you're advised to read through the tutorial. After this, you can read through the language reference to learn about the syntax used by dynasm-rs. You can also read through the runtime documentation to learn about the runtime API. The instruction references lists all assembly mnemnonics and formats supported by dynasm-rs. Finally, documentation on the internals on dynasm-rs can be browsed here.
Differences from LuaJit Dynasm
The following list summarizes some of the larger differences between LuaJIT dynasm and dynasm-rs.
- LuaJIT dynasm uses full program analysis, allowing it to compile local and global labels down to enums. Dynasm-rs however uses HashMaps keyed by static strings, meaning label resolution in dynasm-rs can be a bit slower.
- LuaJIT local labels are integer literals. Dynasm-rs local labels are identifiers.
- Dynasm-rs does not (directly) support stand-alone files.
- LuaJIT dynasm uses a special preprocessor which detects lines starting with pipes (
|) as dynasm instructions, dynasm-rs uses the
dynasm!procedural macro with lines starting with semicolons (
- LuaJIT has macros in its invocations, dynasm-rs uses rust macros that expand to
- Dynasm-rs doesn't have typed aliases
- LuaJIT uses the
mov64mnemnonic to encode 64-bit displacement mov. Dynasm-rs uses the
movabsmnemnonic with a 64-bit immediate parameter to encode this.
- Dynasm-rs is not sensitive to the order of parameters inside a memory reference.
- The syntax used for type maps is significantly different. In LuaJit dynasm it is
Type:reg->attrin dynasm-rs it is
reg => Type.attr.