asm_bytes!() { /* proc-macro */ }Expand description
Assemble source text at compile time, producing a &'static [u8] byte slice.
§Syntax
ⓘ
asm_bytes!(ARCH, "assembly source")where ARCH is one of: x86, x86_64, arm, thumb, aarch64, rv32, rv64.
§Examples
ⓘ
use asm_rs_macros::asm_bytes;
// Single instruction
const NOP: &[u8] = asm_bytes!(x86_64, "nop");
assert_eq!(NOP, &[0x90]);
// Multi-instruction with labels
const CODE: &[u8] = asm_bytes!(x86_64, "
start:
xor eax, eax
inc eax
ret
");
// With base address
const BASED: &[u8] = asm_bytes!(x86_64, 0x400000, "mov rax, 1\nret");§Compile-time errors
If the assembly source contains errors, the macro emits a compile-time error
with the full AsmError diagnostic message.