-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_print.rs
More file actions
63 lines (60 loc) · 1.8 KB
/
test_print.rs
File metadata and controls
63 lines (60 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#[cfg(test)]
mod tests {
use binary_room::instruction::*;
use binary_room::translate::*;
use binary_room::utils;
use binary_room::utils::translate_to_file;
use binary_room::utils::START;
const buf: &str = r#"
.buf:
.string "hello world\n"
"#;
#[test]
fn test_print_translate() {
let riscv_asm: Vec<RiscVInstruction> = vec![
RiscVInstruction::Verbatim {
text: buf.to_string(),
},
RiscVInstruction::Verbatim {
text: START.to_string(),
},
// write syscall
RiscVInstruction::Li {
dest: RiscVRegister::A7,
imm: 64,
},
RiscVInstruction::Li {
dest: RiscVRegister::A2,
imm: 14,
},
RiscVInstruction::Lui {
dest: RiscVRegister::A0,
src: RiscVVal::LabelOffset {
label: ".buf".to_string(),
offset: 9998,
},
},
RiscVInstruction::Addl {
dest: RiscVRegister::A1,
src: RiscVRegister::A0,
label: RiscVVal::LabelOffset {
label: ".buf".to_string(),
offset: 9999,
},
},
RiscVInstruction::Li {
dest: RiscVRegister::A0,
imm: 1,
},
RiscVInstruction::ECall,
// exit syscall
RiscVInstruction::Li {
dest: RiscVRegister::A7,
imm: 93,
},
// RiscVInstruction::Li { dest: RiscVRegister::A0, imm: 0 },
RiscVInstruction::ECall,
];
translate_to_file(riscv_asm, "./tests/print/print.arm.s".to_string());
}
}