Suited instructions now use Operand as operand
This commit is contained in:
parent
66afdf9085
commit
40c104f2fe
4 changed files with 31 additions and 30 deletions
|
@ -3,19 +3,18 @@ package hatelace.instructions;
|
||||||
import hatelace.*;
|
import hatelace.*;
|
||||||
|
|
||||||
public class Add extends Instruction {
|
public class Add extends Instruction {
|
||||||
private Address src;
|
|
||||||
private Word imm;
|
|
||||||
private Address dest;
|
private Address dest;
|
||||||
|
private Operand o1, o2;
|
||||||
|
|
||||||
/** Add immediate value to memory address. */
|
/** Add immediate value to memory address. */
|
||||||
public Add(Address src, Word imm, Address dest) {
|
public Add(Operand o1, Operand o2, Address dest) {
|
||||||
this.src = src;
|
this.o1 = o1;
|
||||||
this.imm = imm;
|
this.o2 = o2;
|
||||||
this.dest = dest;
|
this.dest = dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void execute(Memory memory, ProgramCounter PC) {
|
public void execute(Memory memory, ProgramCounter PC) {
|
||||||
memory.write(this.dest, memory.read(this.src).add(this.imm));
|
memory.write(this.dest, this.o1.getWord(memory).add(this.o2.getWord(memory)));
|
||||||
PC.incPC();
|
PC.incPC();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,10 +23,10 @@ public class Add extends Instruction {
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("%s [%s] %s [%s]", this.opcode(), this.src, this.imm, this.dest);
|
return String.format("%s [%s] %s [%s]", this.opcode(), this.o1, this.o2, this.dest);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Object[] operands() {
|
protected Object[] operands() {
|
||||||
return new Object[] { this.src, this.imm, this.dest };
|
return new Object[] { this.o1, this.o2, this.dest };
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,17 +3,17 @@ package hatelace.instructions;
|
||||||
import hatelace.*;
|
import hatelace.*;
|
||||||
|
|
||||||
public class Copy extends Instruction {
|
public class Copy extends Instruction {
|
||||||
private Word imm;
|
private Operand src;
|
||||||
private Address dest;
|
private Address dest;
|
||||||
|
|
||||||
/** Copy immediate value to memory address. */
|
/** Copy immediate value to memory address. */
|
||||||
public Copy(Word imm, Address dest) {
|
public Copy(Operand src, Address dest) {
|
||||||
this.imm = imm;
|
this.src = src;
|
||||||
this.dest = dest;
|
this.dest = dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void execute(Memory memory, ProgramCounter PC) {
|
public void execute(Memory memory, ProgramCounter PC) {
|
||||||
memory.write(this.dest, this.imm);
|
memory.write(this.dest, this.src.getWord(memory));
|
||||||
PC.incPC();
|
PC.incPC();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -22,10 +22,10 @@ public class Copy extends Instruction {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Object[] operands() {
|
protected Object[] operands() {
|
||||||
return new Object[] {this.imm, this.dest};
|
return new Object[] {this.src, this.dest};
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("%s %s [%s]", this.opcode(), this.imm, this.dest);
|
return String.format("%s %s [%s]", this.opcode(), this.src, this.dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,18 +4,20 @@ import hatelace.*;
|
||||||
|
|
||||||
public class JumpEq extends Instruction {
|
public class JumpEq extends Instruction {
|
||||||
private int index;
|
private int index;
|
||||||
private Address src;
|
// private Address src;
|
||||||
private Word imm;
|
// private Word imm;
|
||||||
|
private Operand o1;
|
||||||
|
private Operand o2;
|
||||||
|
|
||||||
/** Conditional jump */
|
/** Conditional jump */
|
||||||
public JumpEq(int index, Address src, Word imm) {
|
public JumpEq(int index, Operand o1, Operand o2) {
|
||||||
this.index = index;
|
this.index = index;
|
||||||
this.src = src;
|
this.o1 = o1;
|
||||||
this.imm = imm;
|
this.o2 = o2;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void execute(Memory memory, ProgramCounter PC) {
|
public void execute(Memory memory, ProgramCounter PC) {
|
||||||
if (this.imm.equals(memory.read(this.src))) {
|
if (this.o1.getWord(memory).equals(this.o2.getWord(memory))) {
|
||||||
PC.setPC(this.index);
|
PC.setPC(this.index);
|
||||||
} else {
|
} else {
|
||||||
PC.incPC();
|
PC.incPC();
|
||||||
|
@ -27,10 +29,10 @@ public class JumpEq extends Instruction {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Object[] operands() {
|
protected Object[] operands() {
|
||||||
return new Object[] {this.index, this.src, this.imm};
|
return new Object[] {this.index, this.o1, this.o2};
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("%s %s [%s] %s", this.opcode(), this.index, this.src, this.imm);
|
return String.format("%s %s [%s] %s", this.opcode(), this.index, this.o1, this.o2);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,19 +3,19 @@ package hatelace.instructions;
|
||||||
import hatelace.*;
|
import hatelace.*;
|
||||||
|
|
||||||
public class Mul extends Instruction {
|
public class Mul extends Instruction {
|
||||||
private Address src1;
|
private Operand o1;
|
||||||
private Address src2;
|
private Operand o2;
|
||||||
private Address dest;
|
private Address dest;
|
||||||
|
|
||||||
/** Multiply contents of two addresses and store the result in a third memory address. */
|
/** Multiply contents of two addresses and store the result in a third memory address. */
|
||||||
public Mul(Address src1, Address src2, Address dest) {
|
public Mul(Operand o1, Operand o2, Address dest) {
|
||||||
this.src1 = src1;
|
this.o1 = o1;
|
||||||
this.src2 = src2;
|
this.o2 = o2;
|
||||||
this.dest = dest;
|
this.dest = dest;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void execute(Memory memory, ProgramCounter PC) {
|
public void execute(Memory memory, ProgramCounter PC) {
|
||||||
memory.write(this.dest, memory.read(this.src1).multiply(memory.read(this.src2)));
|
memory.write(this.dest, this.o1.getWord(memory).multiply(this.o2.getWord(memory)));
|
||||||
PC.incPC();
|
PC.incPC();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -24,10 +24,10 @@ public class Mul extends Instruction {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Object[] operands() {
|
protected Object[] operands() {
|
||||||
return new Object[] { this.src1, this.src2, this.dest };
|
return new Object[] { this.o1, this.o2, this.dest };
|
||||||
}
|
}
|
||||||
|
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return String.format("%s [%s] [%s] [%s]", this.opcode(), this.src1, this.src2, this.dest);
|
return String.format("%s [%s] [%s] [%s]", this.opcode(), this.o1, this.o2, this.dest);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue