Skip to content

Instantly share code, notes, and snippets.

@unnikked
Last active November 10, 2015 17:38
Show Gist options
  • Save unnikked/23773e974f3a980ecc46 to your computer and use it in GitHub Desktop.
Save unnikked/23773e974f3a980ecc46 to your computer and use it in GitHub Desktop.
OISC Implementation in Java
public class OISC {
int programCounter, a, b, c;
void run(int[] memory) {
while (programCounter >= 0) {
/*System.out.printf("-----\n");
for (int i = 0; i < memory.length; i++) {
System.out.printf("%d\t|%d\n", i, memory[i]);
}
System.out.printf("-----\n");*/
a = memory[programCounter];
b = memory[programCounter + 1];
c = memory[programCounter + 2];
if (a < 0 || b < 0) {
programCounter = -1;
} else {
memory[b] = memory[b] - memory[a];
if (memory[b] > 0) {
programCounter += 3;
} else {
programCounter = c;
}
}
}
}
public static void main(String[] args) {
int[] memory = {
10, 9, 3,
9, 11, 6,
9, 9, 9,
0, 2, 5,
};
System.out.printf("-----\n");
for (int i = 0; i < memory.length; i++) {
System.out.printf("%d\t|%d\n", i, memory[i]);
}
System.out.printf("-----\n");
OISC vm = new OISC();
vm.run(memory);
System.out.printf("-----\n");
for (int i = 0; i < memory.length; i++) {
System.out.printf("%d\t|%d\n", i, memory[i]);
}
System.out.printf("-----\n");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment