Instructions

This commit is contained in:
Imbus 2024-04-16 12:54:33 +02:00
parent 04840349a9
commit b301ba7669
3 changed files with 15 additions and 11 deletions

View file

@ -4,20 +4,22 @@ import hatelace.Instruction;
import hatelace.Memory; import hatelace.Memory;
import hatelace.ProgramCounter; import hatelace.ProgramCounter;
import hatelace.IntWord; import hatelace.IntWord;
import hatelace.Word;
import hatelace.Address;
public class Add extends Instruction { public class Add extends Instruction {
private int op1; private Word op1;
private int op2; private Word op2;
private int dest; private Address dest;
public Add(int op1, int op2, int dest) { public Add(Word op1, Word op2, Address dest) {
this.op1 = op1; this.op1 = op1;
this.op2 = op2; this.op2 = op2;
this.dest = dest; this.dest = dest;
} }
public void execute(Memory memory, ProgramCounter PC) { public void execute(Memory memory, ProgramCounter PC) {
memory.write(this.dest, new IntWord(this.op1 + this.op2)); memory.write(this.dest, new IntWord(op1.add(op2)));
PC.incPC(); PC.incPC();
} }

View file

@ -16,7 +16,7 @@ public class Copy extends Instruction {
} }
public void execute(Memory memory, ProgramCounter PC) { public void execute(Memory memory, ProgramCounter PC) {
memory.write(this.address.getAddress(), this.word); memory.write(this.address, this.word);
PC.incPC(); PC.incPC();
} }

View file

@ -1,23 +1,25 @@
package hatelace.instructions; package hatelace.instructions;
import hatelace.Address;
import hatelace.Word;
import hatelace.Instruction; import hatelace.Instruction;
import hatelace.Memory; import hatelace.Memory;
import hatelace.ProgramCounter; import hatelace.ProgramCounter;
import hatelace.IntWord; import hatelace.IntWord;
public class Mul extends Instruction { public class Mul extends Instruction {
private int op1; private Word op1;
private int op2; private Word op2;
private int dest; private Address dest;
public Mul(int op1, int op2, int dest) { public Mul(Word op1, Word op2, Address dest) {
this.op1 = op1; this.op1 = op1;
this.op2 = op2; this.op2 = op2;
this.dest = dest; this.dest = dest;
} }
public void execute(Memory memory, ProgramCounter PC) { public void execute(Memory memory, ProgramCounter PC) {
memory.write(this.dest, new IntWord(this.op1 * this.op2)); memory.write(this.dest, new IntWord(op1.multiply(op2)));
PC.incPC(); PC.incPC();
} }