Example
Stmt |
code |
reg desc |
addr desc
|
|
|
|
|
t 1 =a-b |
mov a,R 0 |
R 0 contains t 1 |
t 1 in R0
|
|
sub b,R 0 |
|
|
t2 =a-c |
mov a,R 1 |
R0 contains t 1 |
t1 in R0 |
|
sub c,R1 |
R 1 contains t2 |
t 2 in R1
|
t3 =t1 +t 2 |
add R 1 ,R0 |
R 0contains t3 |
t3 in R 0
|
|
|
R 1 contains t2 |
t 2 in R1
|
d=t3 +t2 |
add R 1 ,R 0 |
R 0contains d |
d in R0
|
|
mov R 0 ,d |
|
d in R0 and
|
|
|
|
memory
|
|
|
|
|
|
|
|
|
For example, the assignment d := (a - b) + (a - c) + (a - c) might be translated into the following three- address code sequence:
t1 = a - b
t 2 = a - c
t 3 = t 1 + t2
d = t 3 + t2
The code generation algorithm that we discussed would produce the code sequence as shown. Shown alongside are the values of the register and address descriptors as code generation progresses.
|