-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest_echo.rs
More file actions
73 lines (70 loc) · 2.14 KB
/
test_echo.rs
File metadata and controls
73 lines (70 loc) · 2.14 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
64
65
66
67
68
69
70
71
72
73
#[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::ARM_START;
const buf: &str = r#"
.buf:
.string "hello world"
"#;
#[test]
fn test_print_translate() {
let riscv_asm: Vec<RiscVInstruction> = vec![
// RiscVInstruction::Verbatim { text: buf.to_string() },
RiscVInstruction::Verbatim {
text: ARM_START.to_string(),
},
// read syscall
RiscVInstruction::Addi {
dest: RiscVRegister::SP,
src: RiscVRegister::SP,
imm: -32,
}, // sub stack pointer
RiscVInstruction::Li {
dest: RiscVRegister::A7,
imm: 63,
}, // read syscall #
RiscVInstruction::Li {
dest: RiscVRegister::A2,
imm: 32,
}, // read 5 bytes
RiscVInstruction::Mv {
dest: RiscVRegister::A1,
src: RiscVRegister::SP,
},
RiscVInstruction::Li {
dest: RiscVRegister::A0,
imm: 0,
},
RiscVInstruction::ECall,
// write syscall
RiscVInstruction::Li {
dest: RiscVRegister::A7,
imm: 64,
},
RiscVInstruction::Li {
dest: RiscVRegister::A2,
imm: 14,
},
RiscVInstruction::Mv {
dest: RiscVRegister::A1,
src: RiscVRegister::SP,
},
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/echo/echo.arm.s".to_string());
}
}