A stack used to record the location of forward branches that need to be fixed up.
Used by: R7, R8, R9, R12.
A stack used to record locations for future use in backward branches.
Used by: R10, R11.
Used to record the locations of exit branches in a loop.
Used by: R37, R49, R50.
Programs and Scopes
R0 | Start of the program. | Set pc and mt to values for starting execution. |
R1 | Start of scope (global, procedure/function) | Check that lexical level less than displaySize . Emit instructions to enter statement scope. |
R2 | Beginning of inline function | Check that lexical level less than displaySize . Emit instructions to enter expression scope. |
R3 | End of declarations | Emit instructions to allocate variables (if required) and prepare scope for execution. |
R4 | Before returning from a function | Emit instructions to obtain address for result. |
R5 | End of scope | Emit instructions to free variables and prepare to exit statement scope. |
R6 | End of in-line function | Emit instructions to move result down, free variables, and prepare to exit expression scope. |
R38 | Last statement in program | Emit Halt. |
If and Loop Constructs
R7 | After ELSE statement, before body of functions and procedures | Emit forward unconditional branch. Record address of instruction in FBS. |
R8 | Conditional in IF and WHILE | Emit forward branch on false. Record address of instruction in FBS. |
R9 | After THEN or ELSE part of IF statement, body of WHILE loop, or body of procedure/function | Fix-up address of forward branch identified by top entry of FBS to current location. Pop FBS. |
R10 | Before body of LOOP or WHILE | Push current location onto BBS. |
R11 | After body of LOOP or WHILE | Emit unconditional branch to address on top of BBS. Pop BBS. |
R12 | After ELSE statement | Interchange top two entries in FBS. |
R37 | EXIT expression | Emit forward branch for exit. Record instruction address in LES. |
R49 | Before body of LOOP | Push LES. |
R50 | After body of LOOP | Fixup branches described by top entry in LES to current location. Pop LES. |
Expressions, Input & Output
R13 | UNARY MINUS operator | Emit instructions appropriate to operator. |
R14 | PLUS operator | Emit instructions appropriate to operator. |
R15 | MINUS operator | Emit instructions appropriate to operator. |
R16 | MULTIPLY operator | Emit instructions appropriate to operator. |
R17 | DIVIDE operator | Emit instructions appropriate to operator. |
R18 | EXPONENT operator | Emit instructions appropriate to operator. |
R19 | AND operator | Emit instructions appropriate to operator. |
R20 | OR operator | Emit instructions appropriate to operator. |
R21 | EQUAL operator | Emit instructions appropriate to operator. |
R22 | NOT EQUAL operator | Emit instructions appropriate to operator. |
R23 | LESS THAN operator | Emit instructions appropriate to operator. |
R24 | LESS THAN OR EQUAL TO operator | Emit instructions appropriate to operator. |
R25 | GREATER THAN operator | Emit instructions appropriate to operator. |
R26 | GREATER THAN OR EQUAL TO operator | Emit instructions appropriate to operator. |
R27 | GET integer | Emit instructions to read and store integer. |
R28 | PUT integer | Emit instructions to print integer. |
R29 | PUT string constant | Emit instructions to print text. | R30 | SKIP statement | Emit instructions to skip to new line on output. |
R31 | Need address of variable, e.g., during assignment | Emit instructions to obtain address of variable. |
R32 | Need value of variable, e.g., during call-by-value | Emit instructions to obtain value of variable. |
R33 | Storage (e.g., assignment) | Emit STORE. |
R34 | Boolean value FALSE | Emit PUSH 0. |
R35 | Boolean value TRUE | Emit PUSH 1. |
R36 | Integer constant | Emit PUSH integer value. |
Scalars and Arrays.
R39 | Array variable declaration | Emit instructions to allocate storage for an array variable. |
R40 | Beginning of subscript computation | Emit instructions to obtain address of an array variable. |
R41 | End of subscript computation | Emit instructions to check that index is in bounds. Emit instructions to create address of array element. | R42 | Scalar variable declaration | Emit instructions to allocate storage for a scalar variable. |
Functions, procedures and arguments.
R43 | Right before returning from a function/procedure | Emit instructions to return from a function or procedure. |
R44 | Procedure call | Emit instructions to call a procedure. |
R45 | Start of list of actual parameters to a procedure | Emit instructions to generate block mark for procedure call. |
R46 | Start of list of actual parameters to a function | Emit instructions to generate block mark for function call. |
R47 | Function call | Emit instructions to call function. |
R48 | Actual parameter to function/procedure | Emit instructions to save argument for call. |
Note: Depending on the implementation decisions that you make, some of these code generation actions may be no-ops.