36 lines
835 B
Java
36 lines
835 B
Java
package hatelace.instructions;
|
|
|
|
import hatelace.*;
|
|
|
|
public class JumpEq extends Instruction {
|
|
private int index;
|
|
private Address src;
|
|
private Word imm;
|
|
|
|
/** Conditional jump */
|
|
public JumpEq(int index, Address src, Word imm) {
|
|
this.index = index;
|
|
this.src = src;
|
|
this.imm = imm;
|
|
}
|
|
|
|
public void execute(Memory memory, ProgramCounter PC) {
|
|
if (this.imm.equals(memory.read(this.src))) {
|
|
PC.setPC(this.index);
|
|
} else {
|
|
PC.incPC();
|
|
}
|
|
}
|
|
|
|
protected String opcode() {
|
|
return "JEQ";
|
|
}
|
|
|
|
protected Object[] operands() {
|
|
return new Object[] {this.index, this.src, this.imm};
|
|
}
|
|
|
|
public String toString() {
|
|
return String.format("%s %s [%s] %s", this.opcode(), this.index, this.src, this.imm);
|
|
}
|
|
}
|