Working generic word width

This commit is contained in:
Imbus 2024-04-16 12:42:57 +02:00
parent 1dab9e69c7
commit 04840349a9
11 changed files with 143 additions and 48 deletions

View file

@ -3,6 +3,7 @@ package hatelace.instructions;
import hatelace.Instruction;
import hatelace.Memory;
import hatelace.ProgramCounter;
import hatelace.IntWord;
public class Add extends Instruction {
private int op1;
@ -16,7 +17,7 @@ public class Add extends Instruction {
}
public void execute(Memory memory, ProgramCounter PC) {
memory.write(this.dest, this.op1 + this.op2);
memory.write(this.dest, new IntWord(this.op1 + this.op2));
PC.incPC();
}

View file

@ -0,0 +1,30 @@
package hatelace.instructions;
import hatelace.Address;
import hatelace.Word;
import hatelace.Memory;
import hatelace.ProgramCounter;
import hatelace.Instruction;
public class Copy extends Instruction {
private Word word;
private Address address;
public Copy(Word word, Address address) {
this.word = word;
this.address = address;
}
public void execute(Memory memory, ProgramCounter PC) {
memory.write(this.address.getAddress(), this.word);
PC.incPC();
}
protected String opcode() {
return "copy";
}
protected Object[] operands() {
return new Object[] {this.word, this.address};
}
}

View file

@ -3,6 +3,7 @@ package hatelace.instructions;
import hatelace.Instruction;
import hatelace.Memory;
import hatelace.ProgramCounter;
import hatelace.IntWord;
public class Mul extends Instruction {
private int op1;
@ -16,7 +17,7 @@ public class Mul extends Instruction {
}
public void execute(Memory memory, ProgramCounter PC) {
memory.write(this.dest, this.op1 * this.op2);
memory.write(this.dest, new IntWord(this.op1 * this.op2));
PC.incPC();
}