-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRARSInterface.java
50 lines (39 loc) · 1.2 KB
/
RARSInterface.java
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
package com;
import rars.AssemblyException;
import rars.SimulationException;
import rars.api.Options;
import rars.api.Program;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class RARSInterface
{
public static void main(String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
StringBuilder sb = new StringBuilder();
String line;
while ((line = br.readLine()) != null) {
sb.append(line);
sb.append("\n");
}
Options op = new Options();
op.startAtMain = true;
op.maxSteps = 1000000;
Program p = new Program(op);
try {
p.assembleString(sb.toString());
} catch (AssemblyException ae){
throw new RuntimeException(ae);
}
p.setup(null, "");
// Potentially set memory or registers here
try {
System.out.println(p.simulate());
} catch (SimulationException se){
throw new RuntimeException(se);
}
// check any final register or memory state
System.out.println(p.getRegisterValue("a0"));
}
}