Skip to content

Instantly share code, notes, and snippets.

@unnikked
Last active November 10, 2015 17:38

Revisions

  1. unnikked revised this gist Nov 10, 2015. 1 changed file with 2 additions and 2 deletions.
    4 changes: 2 additions & 2 deletions OISC.java
    Original 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");
    /*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");
    System.out.printf("-----\n");*/
    a = memory[programCounter];
    b = memory[programCounter + 1];
    c = memory[programCounter + 2];
  2. unnikked created this gist Sep 16, 2015.
    53 changes: 53 additions & 0 deletions OISC.java
    Original 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");

    }
    }