-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSAPSimulator.java
More file actions
87 lines (76 loc) · 2.11 KB
/
SAPSimulator.java
File metadata and controls
87 lines (76 loc) · 2.11 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
import java.io.PrintStream;
public class SAPSimulator{
private ALU alu;
private Accumulator acc;
private BRegister bReg;
private BinaryDisplay binDisplay;
private ControlUnitSequencer cu;
private InstructionRegister ir;
private MemoryAddressRegister mar;
private OutputRegister or;
private ProgramCounter pc;
private RandomAccessMemory ram;
public SAPSimulator(String[] memory){
// create objects for registers
pc=new ProgramCounter();
cu=new ControlUnitSequencer();
ram=new RandomAccessMemory(memory);
acc=new Accumulator();
bReg=new BRegister();
binDisplay=new BinaryDisplay();
ir=new InstructionRegister();
mar=new MemoryAddressRegister(ram);
or=new OutputRegister();
alu=new ALU();
}
public void start(PrintStream out){
// simulation
// Initial state - T0
cu.setState(0);
out.println("T0");
out.println(this);
// Address state - T1
cu.setState(1);
out.println("T1");
mar.setData(pc.getCtMar());
out.println(this);
// Increment state - T2
cu.setState(2);
out.println("T2");
pc.countUp();
out.println(this);
// Memory state - T3
cu.setState(3);
out.println("T3");
ir.setRAMData(mar.getRam());
out.println(this);
// Memory state - T4
mar.setData(ir.getOperand());
cu.setData(ir.getOpCode());
cu.setState(4);
out.println("T4");
out.println(this);
// Memory state - T5
cu.setState(5);
out.println("T5");
acc.setData(ram.getFromMemory(mar.getData()));
out.println(this);
// Memory state - T6
cu.setState(6);
out.println("T6");
out.println(this);
}
public String toString(){
String result="";
result+="PC : "+pc.toString()+"\n";
result+="MAR : "+mar.toString()+"\n";
result+="IR : "+ir.toString()+"\n";
result+="CU : "+cu.toString()+"\n";
result+="ACC : "+acc.toString()+"\n";
result+="ALU : "+alu.toString()+"\n";
result+="RB : "+bReg.toString()+"\n";
result+="OR : "+or.toString()+"\n";
result+="BD : "+binDisplay.toString()+"\n";
return result;
}
}