Skip to main content

assemble

Function assemble 

Source
pub fn assemble(source: &str, arch: Arch) -> Result<Vec<u8>, AsmError>
Expand description

Assemble a string of assembly into machine code bytes.

Semicolons or newlines separate instructions. Labels are defined with a trailing colon: loop:

§Errors

Returns AsmError if the input contains syntax errors, unknown mnemonics, invalid operand combinations, undefined labels, or any other encoding issue.

§Examples

use asm_rs::{assemble, Arch};

let code = assemble("nop", Arch::X86_64).unwrap();
assert_eq!(code, vec![0x90]);