PutInt:
PROC [i:
INT] = {
stack: ARRAY [0..10] OF CHAR;
nChars: INT ¬ 0;
negative: BOOL ¬ FALSE;
IF i<0 THEN {i¬-i; negative¬TRUE};
DO
digit: NAT ¬ i MOD 10;
stack[nChars] ¬ VAL['0.ORD + digit];
nChars ¬ nChars + 1;
IF i < 10 THEN EXIT;
i ¬ i / 10;
ENDLOOP;
IF negative
THEN {
stack[nChars] ¬ '-;
nChars ¬ nChars + 1;
};
PutChar[' ];
FOR n:
NAT
DECREASING
IN [0 .. nChars)
DO
PutChar[stack[n]];
ENDLOOP;
};
}.