Compare commits
	
		
			2 commits
		
	
	
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
| 
							 | 
						422344097b | ||
| 
							 | 
						1bdb35a899 | 
					 11 changed files with 36 additions and 39 deletions
				
			
		| 
						 | 
					@ -1,11 +1,8 @@
 | 
				
			||||||
package hatelace;
 | 
					package hatelace;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public abstract class Instruction {
 | 
					public interface Instruction {
 | 
				
			||||||
    public abstract void execute(Memory memory, ProgramCounter pc);
 | 
					    void execute(Memory memory, ProgramCounter pc);
 | 
				
			||||||
 | 
					    String opcode();
 | 
				
			||||||
    protected abstract String opcode();
 | 
					    Object[] operands();
 | 
				
			||||||
 | 
					    String toString();
 | 
				
			||||||
    protected abstract Object[] operands();
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    public abstract String toString();
 | 
					 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -1,11 +1,11 @@
 | 
				
			||||||
package hatelace;
 | 
					package hatelace;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public abstract class Word {
 | 
					public interface Word {
 | 
				
			||||||
    public abstract <T> T getValue();
 | 
					    <T> T getValue();
 | 
				
			||||||
    public abstract Word add(Word other);
 | 
					    Word add(Word other);
 | 
				
			||||||
    public abstract Word subtract(Word other);
 | 
					    Word subtract(Word other);
 | 
				
			||||||
    public abstract Word multiply(Word other);
 | 
					    Word multiply(Word other);
 | 
				
			||||||
    public abstract Word divide(Word other);
 | 
					    Word divide(Word other);
 | 
				
			||||||
    public abstract String toString();
 | 
					    String toString();
 | 
				
			||||||
    public abstract boolean equals(Object other);
 | 
					    boolean equals(Object other);
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@ package hatelace.instructions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import hatelace.*;
 | 
					import hatelace.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class Add extends Instruction {
 | 
					public class Add implements Instruction {
 | 
				
			||||||
    private Address src;
 | 
					    private Address src;
 | 
				
			||||||
    private Word imm;
 | 
					    private Word imm;
 | 
				
			||||||
    private Address dest;
 | 
					    private Address dest;
 | 
				
			||||||
| 
						 | 
					@ -19,7 +19,7 @@ public class Add extends Instruction {
 | 
				
			||||||
        PC.incPC();
 | 
					        PC.incPC();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected String opcode() {
 | 
					    public String opcode() {
 | 
				
			||||||
        return "ADD";
 | 
					        return "ADD";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -27,7 +27,7 @@ public class Add extends Instruction {
 | 
				
			||||||
        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.src, this.imm, this.dest);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected Object[] operands() {
 | 
					    public Object[] operands() {
 | 
				
			||||||
        return new Object[] { this.src, this.imm, this.dest };
 | 
					        return new Object[] { this.src, this.imm, this.dest };
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@ package hatelace.instructions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import hatelace.*;
 | 
					import hatelace.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class Copy extends Instruction {
 | 
					public class Copy implements Instruction {
 | 
				
			||||||
    private Word imm;
 | 
					    private Word imm;
 | 
				
			||||||
    private Address dest;
 | 
					    private Address dest;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -17,11 +17,11 @@ public class Copy extends Instruction {
 | 
				
			||||||
        PC.incPC();
 | 
					        PC.incPC();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected String opcode() {
 | 
					    public String opcode() {
 | 
				
			||||||
        return "CPY";
 | 
					        return "CPY";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected Object[] operands() {
 | 
					    public Object[] operands() {
 | 
				
			||||||
        return new Object[] {this.imm, this.dest};
 | 
					        return new Object[] {this.imm, this.dest};
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@ package hatelace.instructions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import hatelace.*;
 | 
					import hatelace.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class Halt extends Instruction {
 | 
					public class Halt implements Instruction {
 | 
				
			||||||
    /** Halts the CPU */
 | 
					    /** Halts the CPU */
 | 
				
			||||||
    public Halt(){};
 | 
					    public Halt(){};
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -10,11 +10,11 @@ public class Halt extends Instruction {
 | 
				
			||||||
        PC.halt();
 | 
					        PC.halt();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected String opcode() {
 | 
					    public String opcode() {
 | 
				
			||||||
        return "HLT";
 | 
					        return "HLT";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected Object[] operands() {
 | 
					    public Object[] operands() {
 | 
				
			||||||
        return new Object[] {};
 | 
					        return new Object[] {};
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@ package hatelace.instructions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import hatelace.*;
 | 
					import hatelace.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class Jump extends Instruction {
 | 
					public class Jump implements Instruction {
 | 
				
			||||||
    private int index;
 | 
					    private int index;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** Unconditional jump, non-relative */
 | 
					    /** Unconditional jump, non-relative */
 | 
				
			||||||
| 
						 | 
					@ -14,11 +14,11 @@ public class Jump extends Instruction {
 | 
				
			||||||
        PC.setPC(this.index);
 | 
					        PC.setPC(this.index);
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected String opcode() {
 | 
					    public String opcode() {
 | 
				
			||||||
        return "JMP";
 | 
					        return "JMP";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected Object[] operands() {
 | 
					    public Object[] operands() {
 | 
				
			||||||
        return new Object[] {this.index};
 | 
					        return new Object[] {this.index};
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@ package hatelace.instructions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import hatelace.*;
 | 
					import hatelace.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class JumpEq extends Instruction {
 | 
					public class JumpEq implements Instruction {
 | 
				
			||||||
    private int index;
 | 
					    private int index;
 | 
				
			||||||
    private Address src;
 | 
					    private Address src;
 | 
				
			||||||
    private Word imm;
 | 
					    private Word imm;
 | 
				
			||||||
| 
						 | 
					@ -22,11 +22,11 @@ public class JumpEq extends Instruction {
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected String opcode() {
 | 
					    public String opcode() {
 | 
				
			||||||
        return "JEQ";
 | 
					        return "JEQ";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected Object[] operands() {
 | 
					    public Object[] operands() {
 | 
				
			||||||
        return new Object[] {this.index, this.src, this.imm};
 | 
					        return new Object[] {this.index, this.src, this.imm};
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@ package hatelace.instructions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import hatelace.*;
 | 
					import hatelace.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class Mul extends Instruction {
 | 
					public class Mul implements Instruction {
 | 
				
			||||||
    private Address src1;
 | 
					    private Address src1;
 | 
				
			||||||
    private Address src2;
 | 
					    private Address src2;
 | 
				
			||||||
    private Address dest;
 | 
					    private Address dest;
 | 
				
			||||||
| 
						 | 
					@ -19,11 +19,11 @@ public class Mul extends Instruction {
 | 
				
			||||||
        PC.incPC();
 | 
					        PC.incPC();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected String opcode() {
 | 
					    public String opcode() {
 | 
				
			||||||
        return "MUL";
 | 
					        return "MUL";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected Object[] operands() {
 | 
					    public Object[] operands() {
 | 
				
			||||||
        return new Object[] { this.src1, this.src2, this.dest };
 | 
					        return new Object[] { this.src1, this.src2, this.dest };
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@ package hatelace.instructions;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import hatelace.*;
 | 
					import hatelace.*;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class Print extends Instruction {
 | 
					public class Print implements Instruction {
 | 
				
			||||||
    private Address address;
 | 
					    private Address address;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    /** Print content of memory address */
 | 
					    /** Print content of memory address */
 | 
				
			||||||
| 
						 | 
					@ -15,11 +15,11 @@ public class Print extends Instruction {
 | 
				
			||||||
        PC.incPC();
 | 
					        PC.incPC();
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected String opcode() {
 | 
					    public String opcode() {
 | 
				
			||||||
        return "PRT";
 | 
					        return "PRT";
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    protected Object[] operands() {
 | 
					    public Object[] operands() {
 | 
				
			||||||
        return new Object[] { this.address };
 | 
					        return new Object[] { this.address };
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@ package hatelace.memtypes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import hatelace.Word;
 | 
					import hatelace.Word;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class IntWord extends Word {
 | 
					public class IntWord implements Word {
 | 
				
			||||||
    private Integer value;
 | 
					    private Integer value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public IntWord(Integer value) {
 | 
					    public IntWord(Integer value) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -2,7 +2,7 @@ package hatelace.memtypes;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
import hatelace.Word;
 | 
					import hatelace.Word;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
public class LongWord extends Word {
 | 
					public class LongWord implements Word {
 | 
				
			||||||
    private Long value;
 | 
					    private Long value;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    public LongWord(Long value) {
 | 
					    public LongWord(Long value) {
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
	Add table
		Add a link
		
	
		Reference in a new issue