diff --git a/app/src/main/java/hatelace/Instruction.java b/app/src/main/java/hatelace/Instruction.java index 74e72b2..f7d04be 100644 --- a/app/src/main/java/hatelace/Instruction.java +++ b/app/src/main/java/hatelace/Instruction.java @@ -7,17 +7,5 @@ public abstract class Instruction { protected abstract Object[] operands(); - @Override - public String toString() { - // Buffer to hold our formatted instruction - StringBuilder sb = new StringBuilder(); - sb.append(this.opcode()); - - for (Object operand : this.operands()) { - sb.append(" "); - sb.append(operand.toString()); - } - - return sb.toString(); - } + public abstract String toString(); } diff --git a/app/src/main/java/hatelace/instructions/Add.java b/app/src/main/java/hatelace/instructions/Add.java index 76b3115..fc5c2ab 100644 --- a/app/src/main/java/hatelace/instructions/Add.java +++ b/app/src/main/java/hatelace/instructions/Add.java @@ -20,7 +20,11 @@ public class Add extends Instruction { } protected String opcode() { - return "add"; + return "ADD"; + } + + public String toString() { + return String.format("%s [%s] %s [%s]", this.opcode(), this.src, this.imm, this.dest); } protected Object[] operands() { diff --git a/app/src/main/java/hatelace/instructions/Copy.java b/app/src/main/java/hatelace/instructions/Copy.java index 9521879..985ce1a 100644 --- a/app/src/main/java/hatelace/instructions/Copy.java +++ b/app/src/main/java/hatelace/instructions/Copy.java @@ -18,10 +18,14 @@ public class Copy extends Instruction { } protected String opcode() { - return "copy"; + return "CPY"; } protected Object[] operands() { return new Object[] {this.imm, this.dest}; } + + public String toString() { + return String.format("%s %s [%s]", this.opcode(), this.imm, this.dest); + } } diff --git a/app/src/main/java/hatelace/instructions/Halt.java b/app/src/main/java/hatelace/instructions/Halt.java index 569f868..7823e35 100644 --- a/app/src/main/java/hatelace/instructions/Halt.java +++ b/app/src/main/java/hatelace/instructions/Halt.java @@ -10,15 +10,15 @@ public class Halt extends Instruction { PC.halt(); } - public String toString() { - return "HALT"; - } - protected String opcode() { - return "halt"; + return "HLT"; } protected Object[] operands() { return new Object[] {}; } + + public String toString() { + return this.opcode(); + } } diff --git a/app/src/main/java/hatelace/instructions/Jump.java b/app/src/main/java/hatelace/instructions/Jump.java index 373dcb0..972945f 100644 --- a/app/src/main/java/hatelace/instructions/Jump.java +++ b/app/src/main/java/hatelace/instructions/Jump.java @@ -15,10 +15,14 @@ public class Jump extends Instruction { } protected String opcode() { - return "jump"; + return "JMP"; } protected Object[] operands() { return new Object[] {this.index}; } + + public String toString() { + return String.format("%s %s", this.opcode(), this.index); + } } diff --git a/app/src/main/java/hatelace/instructions/JumpEq.java b/app/src/main/java/hatelace/instructions/JumpEq.java index ecfc138..f2538be 100644 --- a/app/src/main/java/hatelace/instructions/JumpEq.java +++ b/app/src/main/java/hatelace/instructions/JumpEq.java @@ -23,10 +23,14 @@ public class JumpEq extends Instruction { } protected String opcode() { - return "jumpeq"; + return "JEQ"; } protected Object[] operands() { return new Object[] {this.index, this.src, this.imm}; } + + public String toString() { + return String.format("%s %s [%s] %s", this.opcode(), this.index, this.src, this.imm); + } } diff --git a/app/src/main/java/hatelace/instructions/Mul.java b/app/src/main/java/hatelace/instructions/Mul.java index d70cb0b..cd61d81 100644 --- a/app/src/main/java/hatelace/instructions/Mul.java +++ b/app/src/main/java/hatelace/instructions/Mul.java @@ -20,10 +20,14 @@ public class Mul extends Instruction { } protected String opcode() { - return "mul"; + return "MUL"; } protected Object[] operands() { return new Object[] { this.src1, this.src2, this.dest }; } + + public String toString() { + return String.format("%s [%s] [%s] [%s]", this.opcode(), this.src1, this.src2, this.dest); + } } diff --git a/app/src/main/java/hatelace/instructions/Print.java b/app/src/main/java/hatelace/instructions/Print.java index 88f0f6c..17e7ce6 100644 --- a/app/src/main/java/hatelace/instructions/Print.java +++ b/app/src/main/java/hatelace/instructions/Print.java @@ -16,10 +16,14 @@ public class Print extends Instruction { } protected String opcode() { - return "print"; + return "PRT"; } protected Object[] operands() { - return new Object[] {this.address}; - } + return new Object[] { this.address }; + } + + public String toString() { + return String.format("%s [%s]", this.opcode(), this.address); + } }