package rebelsky.pal; /** * The basic float add instruction in PAL. * * @author Samuel A. Rebelsky * @version 1.1 of December 2002. */ public class FAdd implements Instruction { // +--------+------------------------------------------------------------ // | Fields | // +--------+ /** The left operand of the addition. */ Variable left; /** The right operand of the addition. */ Variable right; /** The destination of the addition. */ Variable destination; // +--------------+------------------------------------------------------ // | Constructors | // +--------------+ /** * Create a new instruction to add two values and store the * result in destination. */ public FAdd(Variable left, Variable right, Variable destination) { this.left = left; this.right = right; this.destination = destination; } // FAdd(Variable,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, (left.fget(hal)+right.fget(hal))); } // execute(Computer) /** Convert the instruction to a string (usually for printing). */ public String toString() { return " FADD " + left.toString() + ", " + right.toString() + " -> " + destination.toString(); } // toString() } // class FAdd