-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssemblerTest.java
More file actions
62 lines (58 loc) · 2.36 KB
/
AssemblerTest.java
File metadata and controls
62 lines (58 loc) · 2.36 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
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
class AssemblerTest {
private final String[][] instructions = {
{"add r1 r2","fffftffffftffftf"},
{"syscall 100","ftfffffffttfftff"},
{"return","ftftffffffffffff"} ,
{"subtract 10 r4","fftfttftftffftff"} ,
{"halt","ffffffffffffffff"} ,
{"and r7 r13","ffftfffftttfttft"},
{"and 7 r13","ffftftfftttfttft"},
{"multiply r31 r0","fffttftttttfffff"},
{"leftshift 2 r6","fftfftffftfffttf"},
{"or -6 r9","ffttftttftfftfft"},
{"rightshift 0 r2","ffttttfffffffftf"},
{"call 1010","ftfftfttttttfftf"},
{"call 543","ftfftftffffttttt"},
{"call -1023","ftffttffffffffft"},
{"call -824","ftffttffttfftfff"},
{"compare r18 r29","ftfttftfftftttft"},
{"ble -100","fttffttttfftttff"},
{"blt 100","fttftffffttfftff"},
{"bge -100","ftttfttttfftttff"},
{"bgt 100","fttttffffttfftff"},
{"beq -100","tffffttttfftttff"},
{"bne 100","tffftffffttfftff"},
{"load r31 r0", "tfftfftttttfffff"},
{"load 2 r6", "tfftftffftfffttf"},
{"store r31 r0","tffttftttttfffff"},
{"store 2 r6", "tfftttffftfffttf"},
{"copy r31 r0","tftffftttttfffff"},
{"copy 2 r6", "tftfftffftfffttf"},
};
@Test
void assemble() {
var myFirstProgram = new String[] {
"add r1 r2",
"syscall 100",
"return",
"subtract 10 r4"
};
var response = Assembler.assemble(myFirstProgram);
assertEquals("fffftffffftffftf",response[0]);
assertEquals("ftfffffffttfftff",response[1]);
assertEquals("ftftffffffffffff",response[2]);
assertEquals("fftfttftftffftff",response[3]);
}
@Test
void testInstructions() {
for (var instruction : instructions) {
var prog = new String[1];
prog[0] = instruction[0];
assertEquals(16,instruction[1].length(), "Instruction " + instruction[0] + " correct answer is wrong length");
var result = Assembler.assemble(prog);
assertEquals(instruction[1],result[0],"Instruction " + instruction[0] + " failed");
}
}
}