Working add/mul
This commit is contained in:
parent
a60862ed9d
commit
1dab9e69c7
8 changed files with 97 additions and 41 deletions
30
app/src/main/java/hatelace/instructions/Add.java
Normal file
30
app/src/main/java/hatelace/instructions/Add.java
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package hatelace.instructions;
|
||||
|
||||
import hatelace.Instruction;
|
||||
import hatelace.Memory;
|
||||
import hatelace.ProgramCounter;
|
||||
|
||||
public class Add extends Instruction {
|
||||
private int op1;
|
||||
private int op2;
|
||||
private int dest;
|
||||
|
||||
public Add(int op1, int op2, int dest) {
|
||||
this.op1 = op1;
|
||||
this.op2 = op2;
|
||||
this.dest = dest;
|
||||
}
|
||||
|
||||
public void execute(Memory memory, ProgramCounter PC) {
|
||||
memory.write(this.dest, this.op1 + this.op2);
|
||||
PC.incPC();
|
||||
}
|
||||
|
||||
protected String opcode() {
|
||||
return "add";
|
||||
}
|
||||
|
||||
protected Object[] operands() {
|
||||
return new Object[] {this.op1, this.op2, this.dest};
|
||||
}
|
||||
}
|
||||
30
app/src/main/java/hatelace/instructions/Mul.java
Normal file
30
app/src/main/java/hatelace/instructions/Mul.java
Normal file
|
|
@ -0,0 +1,30 @@
|
|||
package hatelace.instructions;
|
||||
|
||||
import hatelace.Instruction;
|
||||
import hatelace.Memory;
|
||||
import hatelace.ProgramCounter;
|
||||
|
||||
public class Mul extends Instruction {
|
||||
private int op1;
|
||||
private int op2;
|
||||
private int dest;
|
||||
|
||||
public Mul(int op1, int op2, int dest) {
|
||||
this.op1 = op1;
|
||||
this.op2 = op2;
|
||||
this.dest = dest;
|
||||
}
|
||||
|
||||
public void execute(Memory memory, ProgramCounter PC) {
|
||||
memory.write(this.dest, this.op1 * this.op2);
|
||||
PC.incPC();
|
||||
}
|
||||
|
||||
protected String opcode() {
|
||||
return "mul";
|
||||
}
|
||||
|
||||
protected Object[] operands() {
|
||||
return new Object[] {this.op1, this.op2, this.dest};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue