HateLace/app/src/main/java/hatelace/instructions/Add.java
2024-04-16 14:24:01 +02:00

32 lines
736 B
Java

package hatelace.instructions;
import hatelace.Instruction;
import hatelace.Memory;
import hatelace.ProgramCounter;
import hatelace.Word;
import hatelace.Address;
public class Add extends Instruction {
private Address op1;
private Word op2;
private Address dest;
public Add(Address op1, Word op2, Address dest) {
this.op1 = op1;
this.op2 = op2;
this.dest = dest;
}
public void execute(Memory memory, ProgramCounter PC) {
memory.write(this.dest, memory.read(this.op1).add(this.op2));
PC.incPC();
}
protected String opcode() {
return "add";
}
protected Object[] operands() {
return new Object[] {this.op1, this.op2, this.dest};
}
}