Contents
Page-10
Prev
Next
Page+10
Index
Arithmetic Expression Algorithm
The genarith input is a tree (operand or operator):
- Operand (leaf node): id or number
- Get a register of the right kind (integer, real)
- An operand may be a variable or constant:
- Variable: Generate an instruction to load the
variable into the register.
- Constant:
- Small constant: Generate an immediate
instruction to load it into the register directly.
- Otherwise, make a literal for the
value of the constant. Generate an instruction to load the literal
into the register.
- Return the register number.
- Operator (interior node):
- Recursively generate code to put each operand into a register.
- Generate the operation on these registers, producing a result
in one of the source registers.
- Mark the other source register unused.
- Return the result register number.