CSC365 Compiler Design and Construction

Compiler Design and ConstructionModel question

Construct the flow graph for the following code and identify all basic blocks: 1. read x 1. i = 1 1. sum = 0 1. prod = 1 1. if i x goto 13 1. square = i i 1. sum = sum + square 1. prod = prod i 1. i…

5

Construct the flow graph for the following code and identify all basic blocks:

  1. read x
  2. i = 1
  3. sum = 0
  4. prod = 1
  5. if i > x goto 13
  6. square = i * i
  7. sum = sum + square
  8. prod = prod * i
  9. i = i + 1
  10. if i <= x goto 6
  11. write sum
  12. write prod
  13. halt

Identify loop invariant code that can be moved out of the loop, if any.

A worked answer is on its wayMeanwhile, read the Compiler Design and Construction notes for this topic.

Discussion

Loading…

More Compiler Design and Construction questions

All Compiler Design and Construction old questions