package rebelsky.pal; /** * The basic move instruction in PAL. * * @author Samuel A. Rebelsky * @version 1.1 of December 2002. */ public class Move implements Instruction { // +--------+------------------------------------------------------------ // | Fields | // +--------+ /** The source of the move. */ Variable source; /** The destination of the move. */ Variable destination; // +--------------+------------------------------------------------------ // | Constructors | // +--------------+ /** * Create a new instruction to move a value from source * to destination. */ public Move(Variable source, Variable destination) { this.source = source; this.destination = destination; } // Move(Variable,Variable) // +---------+----------------------------------------------------------- // | Methods | // +---------+ /** * Execute the instruction on a machine. * * @exception Exception * If one of the memory locations is invalid. * If the destination is a constant or label. */ public void execute(Computer hal) throws Exception { destination.iset(hal, source.iget(hal)); } // execute(Computer) /** Convert the instruction to a string (usually for printing). */ public String toString() { return " MOVE " + source.toString() + " -> " + destination.toString(); } // toString() } // class Move