///////////////////////////////////////////////////////////////////// /// /// This solution contains the classes Instruction, InstructionOne, /// AddIns, and HaltIns. /// ///////////////////////////////////////////////////////////////////// package duckMachine.architecture; /** * The class that represents memory instructions. A memory instruction is * a machine word. * @see Word * @author Amr Sabry * @version jdk-1.1 */ public abstract class Instruction extends Word { public Instruction (int op) { super(op); } } ///////////////////////////////////////////////////////////////////// /// /// InstructionOne /// ///////////////////////////////////////////////////////////////////// /** * The class that represents memory instructions. A memory instruction is * a machine word. * @see Word * @author Amr Sabry * @version jdk-1.1 */ public abstract class InstructionOne extends Instruction { private Address address; private int opcode; public InstructionOne (int op, Address a) { super(op); this.address = a; this.opcode = op; } public Address getAddress () { return address; } public int toInt() { int a = address.toInt(); int b = opcode; b = b << 28; int ans = a | b; return (ans); } } ///////////////////////////////////////////////////////////////////// /// /// ADD Instruction -- note: All instructions that take an /// Address (all but HALT) look very similar to this AddIns, so /// they are not included in this solution. /// ///////////////////////////////////////////////////////////////////// /** * The encapsulation of an ADD instruction. * @author Amr Sabry * @version jdk-1.1 */ public class AddIns extends InstructionOne { public final static int OPCODE = 3; public AddIns (Address a) { super(OPCODE,a); } public String toString () { return "ADD " + super.toString(); } } ///////////////////////////////////////////////////////////////////// /// /// HALT Instruction -- this is the only instruction that does /// not take an Address /// ///////////////////////////////////////////////////////////////////// /** * The encapsulation of a HALT instruction. * @author Amr Sabry * @version jdk-1.1 */ public class HaltIns extends Instruction { public final static int OPCODE = 15; public HaltIns () { super(OPCODE); } public String toString () { return "HALT"; } }