RobotInstructionImpl.mesa
Created Saturday, June 9, 1984 2:25 pm PDT
Last edited by Eric Nickell, October 25, 1984 9:51:09 pm PDT
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];
Current encoding (and therefore decoding) scheme:
#^Ioooootttttttt, where
#  is the immediate bit
^  is the indirect bit
I  is the index bit
ooooo is the opcode number
tttttttt is the tag
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: INTEGERLOOPHOLE[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: BOOLFALSE] ~ {
instruction: RobotDefs.Instruction ← LOOPHOLE[integer];
RETURN [
opNum: instruction.opNum,
tag: instruction.tag,
immediate: instruction.immediate,
indirect: instruction.indirect,
indexed: instruction.indexed
];
};
}.