package rebelsky.pal; /** * The PAL instruction to jump to a destination. Currently fairly * general: You can jump to an address given by any kind of container * not just labels, constants, or registers. * * @author Samuel A. Rebelsky * @version 1.1 of December 2002. */ public class Jump implements Instruction { // +--------+------------------------------------------------------------ // | Fields | // +--------+ /** The container that gives the destination. */ Variable destination; // +--------------+------------------------------------------------------ // | Constructors | // +--------------+ /** * Create a new instruction to jump to a location. */ public Jump(Variable destination) { this.destination = destination; } // Jump(Variable) // +---------+----------------------------------------------------------- // | Methods | // +---------+ /** * Execute the instruction on a machine. * * @exception Exception * If the memory location is invalid. */ public void execute(Computer hal) throws Exception { hal.pc = destination.iget(hal); } // execute(Computer) /** Convert the instruction to a string (usually for printing). */ public String toString() { return " JUMP " + destination.toString(); } // toString() } // class Jump