2024-04-16 07:58:37 +02:00
|
|
|
package hatelace.instructions;
|
|
|
|
|
|
|
|
import hatelace.Instruction;
|
|
|
|
import hatelace.Memory;
|
|
|
|
import hatelace.ProgramCounter;
|
2024-04-16 12:54:33 +02:00
|
|
|
import hatelace.Word;
|
|
|
|
import hatelace.Address;
|
2024-04-16 07:58:37 +02:00
|
|
|
|
|
|
|
public class Add extends Instruction {
|
2024-04-16 14:24:01 +02:00
|
|
|
private Address op1;
|
2024-04-16 12:54:33 +02:00
|
|
|
private Word op2;
|
|
|
|
private Address dest;
|
2024-04-16 07:58:37 +02:00
|
|
|
|
2024-04-16 14:24:01 +02:00
|
|
|
public Add(Address op1, Word op2, Address dest) {
|
2024-04-16 07:58:37 +02:00
|
|
|
this.op1 = op1;
|
|
|
|
this.op2 = op2;
|
|
|
|
this.dest = dest;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void execute(Memory memory, ProgramCounter PC) {
|
2024-04-16 14:24:01 +02:00
|
|
|
memory.write(this.dest, memory.read(this.op1).add(this.op2));
|
2024-04-16 07:58:37 +02:00
|
|
|
PC.incPC();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected String opcode() {
|
|
|
|
return "add";
|
|
|
|
}
|
|
|
|
|
|
|
|
protected Object[] operands() {
|
|
|
|
return new Object[] {this.op1, this.op2, this.dest};
|
|
|
|
}
|
|
|
|
}
|