[prev] 4 [next]

Rendering C in MIPS: Expressions (cont)

Expression evaluation involves
  • describing the process as a sequence of binary operations
  • managing data flow between the operations
Example:

# x = (1 + y*y) / 2

#assume we rewrote this in simplified C as
# t = y*y
# t = 1 + t
# t = t/2
# x  = t

# assume x and y exist as labels in .data
  lw   $t0, y          # t0 = y
  mul  $t0, $t0, $t0   # t0 = y*y
  addi $t0, $t0, 1     # t0 = 1 + t0
  li   $t1, 2          # t1 = 2
  div  $t0, $t0, t1    # t0 = t0/2 (int div)
  sw   $t0, x          # x = t0

It is useful to minimise the number of registered involved in the evaluation