pub enum AssemblyResult {
I(Instruction),
C(CInstruction),
}Variants§
Implementations§
Source§impl AssemblyResult
impl AssemblyResult
pub fn c(self) -> CInstruction
Sourcepub fn i(self) -> Instruction
pub fn i(self) -> Instruction
Examples found in repository?
examples/simple.rs (line 4)
2fn main() {
3 // instruction can be assembled from strings
4 let instr: Instruction = assemble_line("addi t0, t1, 1024").unwrap().i();
5 // and disassembled
6 println!("assembled instruction: {}", instr);
7
8 // instructions can also be decoded from binary
9 let instr2 = Instruction::decode(0xe0058513).unwrap();
10
11 // and encoded
12 assert_eq!(Instruction::encode(&instr2), 0xe0058513);
13
14 let instr2 = assemble_line("fcvt.lu.s zero,ft0,rne").unwrap().i();
15 println!("assembled instruction: {}", instr2);
16}More examples
examples/all-u32.rs (line 19)
4fn main() {
5 let mut valid: u32 = 0;
6 for x in 0..u32::MAX {
7 if x % 10000 == 0 {
8 println!("{:.4}%", 100.0 * (x as f64) / (u32::MAX as f64))
9 }
10 if let Ok(i) = Instruction::decode(x) {
11 valid += 1;
12 let e = Instruction::encode(&i);
13 if x != e {
14 println!("i: {i}\nx: {x:032b}\ne: {e:032b}");
15 exit(1);
16 }
17
18 let d = i.to_string();
19 let i2 = assemble_line(&d).unwrap().i();
20 if i != i2 {
21 println!("disassembled {i:#?} to get {d}. Assembled to get {i2:#?}!");
22 exit(1);
23 }
24 }
25 }
26 println!("Done.");
27 println!("proportion of encoding space used: {}%", 100.0 * (valid as f64) / (u32::MAX as f64))
28}Trait Implementations§
Source§impl Debug for AssemblyResult
impl Debug for AssemblyResult
Source§impl PartialEq for AssemblyResult
impl PartialEq for AssemblyResult
impl StructuralPartialEq for AssemblyResult
Auto Trait Implementations§
impl Freeze for AssemblyResult
impl RefUnwindSafe for AssemblyResult
impl Send for AssemblyResult
impl Sync for AssemblyResult
impl Unpin for AssemblyResult
impl UnwindSafe for AssemblyResult
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more