Last active
November 10, 2015 17:38
Revisions
-
unnikked revised this gist
Nov 10, 2015 . 1 changed file with 2 additions and 2 deletions.There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -3,11 +3,11 @@ public class OISC { 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]; -
unnikked created this gist
Sep 16, 2015 .There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode charactersOriginal file line number Diff line number Diff line change @@ -0,0 +1,53 @@ 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"); } }