Function solana_rbpf::assembler::assemble [−][src]
pub fn assemble<E: UserDefinedError, I: 'static + InstructionMeter>(
src: &str,
verifier: Option<Verifier>,
config: Config,
syscall_registry: SyscallRegistry
) -> Result<Executable<E, I>, String>
Expand description
Parse assembly source and translate to binary.
Examples
use solana_rbpf::{assembler::assemble, user_error::UserError, vm::{Config, TestInstructionMeter, SyscallRegistry}};
let executable = assemble::<UserError, TestInstructionMeter>(
"add64 r1, 0x605
mov64 r2, 0x32
mov64 r1, r0
be16 r0
neg64 r2
exit",
None,
Config::default(),
SyscallRegistry::default(),
).unwrap();
let program = executable.get_text_bytes().1;
println!("{:?}", program);
This will produce the following output:
[0x07, 0x01, 0x00, 0x00, 0x05, 0x06, 0x00, 0x00,
0xb7, 0x02, 0x00, 0x00, 0x32, 0x00, 0x00, 0x00,
0xbf, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0xdc, 0x00, 0x00, 0x00, 0x10, 0x00, 0x00, 0x00,
0x87, 0x02, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
0x95, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]