Bingo
This commit is contained in:
parent
f7e3b00408
commit
fa804681c2
13 changed files with 150 additions and 15 deletions
|
|
@ -7,18 +7,18 @@ import hatelace.Word;
|
|||
import hatelace.Address;
|
||||
|
||||
public class Add extends Instruction {
|
||||
private Word op1;
|
||||
private Address op1;
|
||||
private Word op2;
|
||||
private Address dest;
|
||||
|
||||
public Add(Word op1, Word op2, 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, op1.add(op2));
|
||||
memory.write(this.dest, memory.read(this.op1).add(this.op2));
|
||||
PC.incPC();
|
||||
}
|
||||
|
||||
|
|
|
|||
23
app/src/main/java/hatelace/instructions/Halt.java
Normal file
23
app/src/main/java/hatelace/instructions/Halt.java
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package hatelace.instructions;
|
||||
|
||||
import hatelace.*;
|
||||
|
||||
public class Halt extends Instruction {
|
||||
public Halt(){};
|
||||
|
||||
public void execute(Memory memory, ProgramCounter PC) {
|
||||
PC.halt();
|
||||
}
|
||||
|
||||
public String toString() {
|
||||
return "HALT";
|
||||
}
|
||||
|
||||
protected String opcode() {
|
||||
return "halt";
|
||||
}
|
||||
|
||||
protected Object[] operands() {
|
||||
return new Object[] {};
|
||||
}
|
||||
}
|
||||
23
app/src/main/java/hatelace/instructions/Jump.java
Normal file
23
app/src/main/java/hatelace/instructions/Jump.java
Normal file
|
|
@ -0,0 +1,23 @@
|
|||
package hatelace.instructions;
|
||||
|
||||
import hatelace.*;
|
||||
|
||||
public class Jump extends Instruction {
|
||||
private int index;
|
||||
|
||||
public Jump(int index) {
|
||||
this.index = index;
|
||||
}
|
||||
|
||||
public void execute(Memory memory, ProgramCounter PC) {
|
||||
PC.setPC(this.index);
|
||||
}
|
||||
|
||||
protected String opcode() {
|
||||
return "jump";
|
||||
}
|
||||
|
||||
protected Object[] operands() {
|
||||
return new Object[] {this.index};
|
||||
}
|
||||
}
|
||||
31
app/src/main/java/hatelace/instructions/JumpEq.java
Normal file
31
app/src/main/java/hatelace/instructions/JumpEq.java
Normal file
|
|
@ -0,0 +1,31 @@
|
|||
package hatelace.instructions;
|
||||
|
||||
import hatelace.*;
|
||||
|
||||
public class JumpEq extends Instruction {
|
||||
private int index;
|
||||
private Address address;
|
||||
private Word value;
|
||||
|
||||
public JumpEq(int index, Address address, Word value) {
|
||||
this.index = index;
|
||||
this.address = address;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public void execute(Memory memory, ProgramCounter PC) {
|
||||
if (this.value.equals(memory.read(this.address))) {
|
||||
PC.setPC(this.index);
|
||||
} else {
|
||||
PC.incPC();
|
||||
}
|
||||
}
|
||||
|
||||
protected String opcode() {
|
||||
return "jumpeq";
|
||||
}
|
||||
|
||||
protected Object[] operands() {
|
||||
return new Object[] {this.index, this.address, this.value};
|
||||
}
|
||||
}
|
||||
|
|
@ -1,24 +1,23 @@
|
|||
package hatelace.instructions;
|
||||
|
||||
import hatelace.Address;
|
||||
import hatelace.Word;
|
||||
import hatelace.Instruction;
|
||||
import hatelace.Memory;
|
||||
import hatelace.ProgramCounter;
|
||||
|
||||
public class Mul extends Instruction {
|
||||
private Word op1;
|
||||
private Word op2;
|
||||
private Address op1;
|
||||
private Address op2;
|
||||
private Address dest;
|
||||
|
||||
public Mul(Word op1, Word op2, Address dest) {
|
||||
public Mul(Address op1, Address op2, Address dest) {
|
||||
this.op1 = op1;
|
||||
this.op2 = op2;
|
||||
this.dest = dest;
|
||||
}
|
||||
|
||||
public void execute(Memory memory, ProgramCounter PC) {
|
||||
memory.write(this.dest, op1.multiply(op2));
|
||||
memory.write(this.dest, memory.read(this.op1).multiply(memory.read(this.op2)));
|
||||
PC.incPC();
|
||||
}
|
||||
|
||||
|
|
|
|||
24
app/src/main/java/hatelace/instructions/Print.java
Normal file
24
app/src/main/java/hatelace/instructions/Print.java
Normal file
|
|
@ -0,0 +1,24 @@
|
|||
package hatelace.instructions;
|
||||
|
||||
import hatelace.*;
|
||||
|
||||
public class Print extends Instruction {
|
||||
private Address address;
|
||||
|
||||
public Print(Address address) {
|
||||
this.address = address;
|
||||
}
|
||||
|
||||
public void execute(Memory memory, ProgramCounter PC) {
|
||||
System.out.println(memory.read(this.address));
|
||||
PC.incPC();
|
||||
}
|
||||
|
||||
protected String opcode() {
|
||||
return "print";
|
||||
}
|
||||
|
||||
protected Object[] operands() {
|
||||
return new Object[] {this.address};
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue