pub mod convert;
pub mod instruction;
pub use instruction::{ Instruction, InstructionBuilder };
pub use ddirective as dd;
pub use operand_label as oplabel;
pub use _instruction as instruction;
pub use _instruction as i;
pub use operand_string as opstring;
pub use operand_expression as opexpr;
pub use register as reg;
pub mod macros {
pub use super::{ instruction, InstructionBuilder };
pub use super::instruction::{ Mnemonic::*, Section::*, Reg::*, DD::*, Op };
pub use crate::{ dd, oplabel, i, opstring, opexpr, reg, section, label };
}
#[cfg(test)]
mod tests {
#[test]
fn example() {
use std::path::Path;
use std::fs::File;
use std::io::prelude::*;
use super::convert::{ ToAssembly, Separator };
use super::macros::*;
let instructions = vec![
i!(Global, oplabel!("_start")),
i!(section!(Text)),
i!(label!("_start")),
i!(Mov, reg!(Rax), Op::Literal(1)),
i!(Mov, reg!(Rdi), Op::Literal(1)),
i!(Mov, reg!(Rsi), oplabel!("msg")),
i!(Mov, reg!(Rdx), oplabel!("msg_len")),
i!(Syscall),
i!(Mov, reg!(Rax), Op::Literal(60)),
i!(Mov, reg!(Rdi), Op::Literal(0)),
i!(Syscall),
i!(section!(Data)),
i!(label!("msg"), dd!(Db), opstring!("Hello world")),
i!(label!("msg_len"), dd!(Equ), opexpr!("$ - msg")),
];
let code = instructions.to_assembly(Separator::Space);
let mut stream = File::create(&Path::new("target/test.asm")).unwrap();
write!(stream, "{}", code).unwrap();
}
}