ReadMicroInstruction:
PROC [inputStream:
FS.
STREAM]
RETURNS [mi: MicroInstruction] ~ {
inputLine: Rope.ROPE;
lineLength: INT;
number: NAT;
inputLine ← IO.GetLineRope[inputStream];
lineLength ← Rope.Length[inputLine];
IF lineLength # microCodeWidth
THEN
SIGNAL
BadInputLineLength[microCodeWidth, lineLength];
At this point we have a ROPE with the right number of chars at least so parse the
ROPE to get all of the appropriate fields. If the positions or size of the uCode bits
change, update the list of positions in MonkeyHeart.mesa
number ← Convert.IntFromRope[Rope.Substr[inputLine, readCxtPos, readCxtLen], 2];
mi.readCxt ← LOOPHOLE[number, BOOL];
number ← Convert.IntFromRope[Rope.Substr[inputLine, writeCxtPos, writeCxtLen], 2];
mi.writeCxt ← LOOPHOLE[number, BOOL];
number ← Convert.IntFromRope[Rope.Substr[inputLine, newTopCxtPos, newTopCxtLen], 2];
mi.newTopCxt ← LOOPHOLE[number, BOOL];
number ← Convert.IntFromRope[Rope.Substr[inputLine, newBotCxtPos, newBotCxtLen], 2];
mi.newBotCxt ← LOOPHOLE[number, BOOL];
number ← Convert.IntFromRope[Rope.Substr[inputLine, altCxtPos, altCxtLen], 2];
mi.altCxt ← LOOPHOLE[number, NAT];
number ← Convert.IntFromRope[Rope.Substr[inputLine, memOpPos, memOpLen], 2];
mi.memOp ← LOOPHOLE[number, NAT];
number ← Convert.IntFromRope[Rope.Substr[inputLine, tagPos, tagLen], 2];
mi.tag ← LOOPHOLE[number, NAT];
number ← Convert.IntFromRope[Rope.Substr[inputLine, euOpPos, euOpLen], 2];
mi.euOp ← LOOPHOLE[number, NAT];
number ← Convert.IntFromRope[Rope.Substr[inputLine, rd1AddrPos, rd1AddrLen], 2];
mi.rd1Addr ← LOOPHOLE[number, NAT];
number ← Convert.IntFromRope[Rope.Substr[inputLine, rd2AddrPos, rd2AddrLen], 2];
mi.rd2Addr ← LOOPHOLE[number, NAT];
number ← Convert.IntFromRope[Rope.Substr[inputLine, dswapPos, dswapLen], 2];
mi.dswap ← LOOPHOLE[number, BOOL];
number ← Convert.IntFromRope[Rope.Substr[inputLine, rAddrPos, rAddrLen], 2];
mi.rAddr ← LOOPHOLE[number, NAT];
number ← Convert.IntFromRope[Rope.Substr[inputLine, waddrPos, waddrLen], 2];
mi.waddr ← LOOPHOLE[number, NAT];
number ← Convert.IntFromRope[Rope.Substr[inputLine, newargPos, newargLen], 2];
mi.newarg ← LOOPHOLE[number, NAT];
number ← Convert.IntFromRope[Rope.Substr[inputLine, newarg2Pos, newarg2Len], 2];
mi.newarg2 ← LOOPHOLE[number, NAT];
number ← Convert.IntFromRope[Rope.Substr[inputLine, newtosPos, newtosLen], 2];
mi.newtos ← LOOPHOLE[number, NAT];
number ← Convert.IntFromRope[Rope.Substr[inputLine, muxreadPos, muxreadLen], 2];
mi.muxread ← LOOPHOLE[number, NAT];
number ← Convert.IntFromRope[Rope.Substr[inputLine, muxwritePos, muxwriteLen], 2];
mi.muxwrite ← LOOPHOLE[number, NAT];
number ← Convert.IntFromRope[Rope.Substr[inputLine, tosPrimePos, tosPrimeLen], 2];
mi.tosPrime ← LOOPHOLE[number, BOOL];
number ← Convert.IntFromRope[Rope.Substr[inputLine, argPrimePos, argPrimeLen], 2];
mi.argPrime ← LOOPHOLE[number, BOOL];
number ← Convert.IntFromRope[Rope.Substr[inputLine, arg2PrimePos, arg2PrimeLen], 2];
mi.arg2Prime ← LOOPHOLE[number, BOOL];
number ← Convert.IntFromRope[Rope.Substr[inputLine, kPos, kLen], 2];
mi.k ← LOOPHOLE[number, NAT];
number ← Convert.IntFromRope[Rope.Substr[inputLine, invertCCodePos, invertCCodeLen], 2];
mi.invertCCode ← LOOPHOLE[number, BOOL];
number ← Convert.IntFromRope[Rope.Substr[inputLine, dpCCodePos, dpCCodeLen], 2];
mi.dpCCode ← LOOPHOLE[number, NAT];
number ← Convert.IntFromRope[Rope.Substr[inputLine, muxCCodePos, muxCCodeLen], 2];
mi.muxCCode ← LOOPHOLE[number, NAT];
number ← Convert.IntFromRope[Rope.Substr[inputLine, resultCCodePos, resultCCodeLen], 2];
mi.resultCCode ← LOOPHOLE[number, NAT];
number ← Convert.IntFromRope[Rope.Substr[inputLine, memCCodePos, memCCodeLen], 2];
mi.memCCode ← LOOPHOLE[number, NAT];
number ← Convert.IntFromRope[Rope.Substr[inputLine, writeOnTruePos, writeOnTrueLen], 2];
mi.writeOnTrue ← LOOPHOLE[number, BOOL];
number ← Convert.IntFromRope[Rope.Substr[inputLine, nextInstAPos, nextInstALen], 2];
mi.nextInstA ← LOOPHOLE[number, NAT];
number ← Convert.IntFromRope[Rope.Substr[inputLine, nextInstBPos, nextInstBLen], 2];
mi.nextInstB ← LOOPHOLE[number, NAT];
number ← Convert.IntFromRope[Rope.Substr[inputLine, miscPos, miscLen], 2];
mi.misc ← LOOPHOLE[number, NAT];
number ← Convert.IntFromRope[Rope.Substr[inputLine, updatePCPos, updatePCLen], 2];
mi.updatePC ← LOOPHOLE[number, BOOL];
number ← Convert.IntFromRope[Rope.Substr[inputLine, opLengthPos, opLengthLen], 2];
mi.opLength ← LOOPHOLE[number, NAT];
RETURN [mi];
};