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