<> <> <> <<>> DIRECTORY RobotDefs USING [Instruction], RobotEvaluator USING [ApplyBinaryFcn, NewValueFromInteger, opMOD, opPlus], RobotInstruction; RobotInstructionImpl: CEDAR PROGRAM IMPORTS RobotEvaluator EXPORTS RobotInstruction ~ { OPEN RobotInstruction; v256: Value _ RobotEvaluator.NewValueFromInteger[256]; <> <<#^Ioooootttttttt, where>> <<# is the immediate bit>> <<^ is the indirect bit>> <> <> <> EncodeStatement: PUBLIC PROC [opNum: INTEGER, tag: Value, immediate, indirect, indexed: BOOL] RETURNS [value: Value] ~ { instruction: RobotDefs.Instruction _ [ immediate: immediate, indirect: indirect, indexed: indexed, opNum: opNum, tag: 0 ]; insValue: INTEGER _ LOOPHOLE[instruction]; value _ RobotEvaluator.ApplyBinaryFcn[ RobotEvaluator.opPlus, RobotEvaluator.ApplyBinaryFcn[RobotEvaluator.opMOD, tag, RobotEvaluator.NewValueFromInteger[256]], RobotEvaluator.NewValueFromInteger[insValue]]; }; DecodeStatement: PUBLIC PROC [integer: INTEGER] RETURNS [opNum, tag: INTEGER, immediate, indirect, indexed: BOOL _ FALSE] ~ { instruction: RobotDefs.Instruction _ LOOPHOLE[integer]; RETURN [ opNum: instruction.opNum, tag: instruction.tag, immediate: instruction.immediate, indirect: instruction.indirect, indexed: instruction.indexed ]; }; }.