package rebelsky.pal; /** * Convert an integer to a float. * * @author Samuel A. Rebelsky * @version 1.1 of December 2002. */ public class I2F implements Instruction { // +--------+------------------------------------------------------------ // | Fields | // +--------+ /** The source of the conversion (the integer). */ Variable source; /** The destination of the conversion (the float). */ Variable destination; // +--------------+------------------------------------------------------ // | Constructors | // +--------------+ /** * Create a new instruction to convert a value. */ public I2F(Variable source, Variable destination) { this.source = source; this.destination = destination; } // I2F(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.fset(hal, (float) source.iget(hal)); } // execute(Computer) /** Convert the instruction to a string (usually for printing). */ public String toString() { return " I2F " + source.toString() + " -> " + destination.toString(); } // toString() } // class I2F