Expand description
§asm-rs — Pure Rust Multi-Architecture Assembly Engine
asm-rs is a pure Rust, zero-C-dependency, multi-architecture runtime assembler
that turns human-readable assembly text into machine-code bytes.
§Quick Start
use asm_rs::{assemble, Arch};
let code = assemble("nop", Arch::X86_64).unwrap();
assert_eq!(code, vec![0x90]);§Features
- Pure Rust — no C/C++ FFI, no LLVM, no system assembler at runtime.
- Multi-arch — x86, x86-64, ARM, AArch64, RISC-V (feature-gated).
- Runtime text parsing — assemble from strings at runtime.
no_std+alloc— embeddable in firmware, kernels, WASM.- Labels & branch relaxation — automatic forward/backward label resolution.
Re-exports§
pub use assembler::Assembler;pub use assembler::AssemblyResult;pub use assembler::ResourceLimits;pub use encoder::RelocKind;pub use error::ArchName;pub use error::AsmError;pub use error::Span;pub use ir::AddrMode;pub use ir::AlignDirective;pub use ir::Arch;pub use ir::BroadcastMode;pub use ir::ConstDef;pub use ir::DataDecl;pub use ir::DataSize;pub use ir::DataValue;pub use ir::Expr;pub use ir::FillDirective;pub use ir::Instruction;pub use ir::MemoryOperand;pub use ir::Mnemonic;pub use ir::Operand;pub use ir::OperandList;pub use ir::OperandSize;pub use ir::OptLevel;pub use ir::OrgDirective;pub use ir::Prefix;pub use ir::PrefixList;pub use ir::Register;pub use ir::SpaceDirective;pub use ir::Statement;pub use ir::SvePredQual;pub use ir::Syntax;pub use ir::VectorArrangement;pub use ir::X86Mode;pub use linker::AppliedRelocation;pub use preprocessor::Preprocessor;
Modules§
- assembler
- Public assembler API — builder pattern, one-shot assembly, and
AssemblyResult. Public assembler API — builder pattern and one-shot assembly. - encoder
- x86-64 instruction encoder (REX, ModR/M, SIB, immediate, relocation). x86-64 instruction encoder.
- error
- Error types and source-span diagnostics. Error types and source span tracking for diagnostics.
- ir
- Intermediate representation: registers, operands, instructions, directives. Intermediate representation types for the assembly pipeline.
- lexer
- Zero-copy lexer (tokenizer) with span tracking. Lexer for assembly source text.
- linker
- Fragment-based linker: label resolution, branch relaxation, patching. Label resolution, branch relaxation, and final layout.
- optimize
- Peephole optimizations for instruction encoding. Peephole optimizations for x86/x86-64 instructions.
- parser
- Intel-syntax parser producing IR statements. Multi-architecture assembly parser.
- preprocessor
- Preprocessor: macros, repeat loops, and conditional assembly. Preprocessor for assembly source text.
Functions§
- assemble
- Assemble a string of assembly into machine code bytes.
- assemble_
at - Assemble with an explicit base virtual address.
- assemble_
with - Assemble with external labels pre-defined at known addresses.