Skip to content
Snippets Groups Projects
Commit 1e3b90c8 authored by Emily Marshall's avatar Emily Marshall
Browse files

Update Machine.java

parent bccf79b3
Branches
No related tags found
No related merge requests found
//abs value of register value in ADD:
//may not be caught if test cases don't include
//negative values for ADD insturction.
package swen90006.machine; package swen90006.machine;
import java.util.Arrays; import java.util.Arrays;
...@@ -58,7 +61,11 @@ public class Machine ...@@ -58,7 +61,11 @@ public class Machine
private void do_add(int dest, int src1, int src2) private void do_add(int dest, int src1, int src2)
{ {
regs[dest] = regs[src1] + regs[src2]; regs[dest] = regs[src1] + abs(regs[src2]);
//abs value of register value in ADD:
//may not be caught if test cases don't include
//negative values for ADD insturction.
} }
private void do_sub(int dest, int src1, int src2) private void do_sub(int dest, int src1, int src2)
...@@ -77,6 +84,7 @@ public class Machine ...@@ -77,6 +84,7 @@ public class Machine
/* no op */ /* no op */
}else{ }else{
regs[dest] = regs[src1] / regs[src2]; regs[dest] = regs[src1] / regs[src2];
} }
} }
...@@ -168,9 +176,10 @@ public class Machine ...@@ -168,9 +176,10 @@ public class Machine
int instructionsExecuted = 0; int instructionsExecuted = 0;
int pc = 0; int pc = 0;
final int progLength = instructions.size(); final int progLength = instructions.size()-1;
while(true){ while(true){
if (pc < 0 || pc >= progLength){ if (pc < 0 || pc >= progLength){
/* will cause NoReturnValueException to be thrown /* will cause NoReturnValueException to be thrown
* but that is not a bug and and indeed is what the * but that is not a bug and and indeed is what the
* VM is supposed to do if the pc becomes negative, * VM is supposed to do if the pc becomes negative,
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment