-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCPU.java
46 lines (28 loc) · 835 Bytes
/
CPU.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
package MaquinaVirtual;
public class CPU {
private IO io;
private RAM ram;
private int pc;
public CPU(IO io, RAM ram) {
this.io = io;
this.ram = ram;
this.pc = 0;
}
public void execute(int address) {
pc = address;
io.print("Executing program at address " + pc+"\n");
while(ram.read(pc) != -1){
int a = ram.read(pc);
++pc;
int b = ram.read(pc);
++pc;
int counter = 0;
for (int i = a; i <= (b); ++i) {
counter += 1;
//System.out.println("Pos "+ i +" Counter: " + counter);
ram.write(i, counter);
io.print(i + " -> " + counter + "\n");
}
}
}
}