GenAcker.mesa
Copyright © 1984 by Xerox Corporation. All rights reserved.
Russ Atkinson, July 19, 1984 11:18:31 pm PDT
Russ Atkinson (RRA) January 10, 1986 3:39:38 pm PST
GenAcker:
CEDAR PROGRAM
IMPORTS HandCoding, HandCodingPseudos
= BEGIN OPEN DragonProcessOffsets, HandCoding, HandCodingSupport, HandCodingPseudos;
CARD: TYPE = LONG CARDINAL;
Word: TYPE = DragOpsCross.Word;
GenAck: PROC [enter: Label] = {
This is the assembly level code for:
Ack: PROC [x,y: INT] RETURNS [ans: INT] = {
SELECT TRUE FROM
x = 0 => ans ← 1;
y = 0 => ans ← IF x = 1 THEN 2 ELSE x+2;
ENDCASE => ans ← Ack[Ack[x-1, y], y-1];
};
rX: RegSpec = reg0;
rY: RegSpec = reg1;
returnLabel: Label = GenLabel[];
ProcedureEntry[enter, 2];
MakeLabelGlobal["Acker.Ack", enter];
{elseLabel: Label = GenLabel[];
drLRn[rX];
drJNEBBJ[0, UseLabel8B[elseLabel]];
drLC1[];
drJB[UseLabel8A[returnLabel]];
SetLabel[elseLabel];
};
{elseLabel: Label = GenLabel[];
drLRn[rY];
drJNEBBJ[0, UseLabel8B[elseLabel]];
{innerElseLabel: Label = GenLabel[];
drLRn[rX];
drJNEBB[1, UseLabel8B[innerElseLabel]];
drLC2[];
drJB[UseLabel8A[returnLabel]];
SetLabel[innerElseLabel];
drRADD[pushDst, rX, const2];
drJB[UseLabel8A[returnLabel]];
};
SetLabel[elseLabel];
};
drRSUB[pushDst, rX, const1];
drLRn[rY];
drLFC[UseLabel16[enter]];
drRSUB[pushDst, rY, const1];
drLFC[UseLabel16[enter]];
SetLabel[returnLabel];
drSRn[reg0];
ProcedureExit[1];
};
All:
PROC = {
GenAcker.All[] is a procedure that gets called by LizardTool to generate the code when GenAcker.bcd is loaded and started.
startLabel: Label = GenLabelHere[];
enterRecurse: Label = GenLabel[];
testLabel: Label = GenLabel[];
MakeLabelGlobal["Acker.Start", startLabel];
EnableTraps[]; -- to detect stack overflow
drASL[255]; -- ensure that stack is empty, regardless of where it was
drJDB[UseLabel16[testLabel]];
GenAck[enterRecurse];
SetLabel[testLabel];
drLIB[11];
drLIB[2];
drLFC[UseLabel16[enterRecurse]];
Halt[0];
};
END.