| node | program | * | + | - | / | a | b | c | d | e |
|---|---|---|---|---|---|---|---|---|---|---|
| next_free_reg | - | 0 | 0 | 1 | 2 | 0 | 1 | 1 | 2 | 3 |
| reg | - | r1 | r1 | r2 | r3 | r1 | r2 | r2 | r3 | r4 |
| code | r1 := a r2 := b r1 := r1 + r2 r2 := c r3 := d r4 := e r3 := r3 / r4 r2 := r2 - r3 r1 := r1 * r2 |
r1 := a r2 := b r1 := r1 + r2 r2 := c r3 := d r4 := e r3 := r3 / r4 r2 := r2 - r3 r1 := r1 * r2 |
r1 := a r2 := b r1 := r1 + r2 |
r2 := c r3 := d r4 := e r3 := r3 / r4 r2 := r2 - r3 |
r3 := d r4 := e r3 := r3 / r4 |
r1 := a | r2 := b | r2 := c | r3 := d | r4 := e |
As a general example, suppose there are 8 registers (4 that the caller saves and 4 that the callee saves), the callee uses 5 registers, and the caller needs to preserve 5 of the registers across the call. The callee can use 4 of the caller-saves registers; it will have to save the 1 other register that it uses. The caller can arrange to put 4 of the 5 values that it needs to saved into the callee-saves registers; it will need to save the 1 remaining register. Thus only 2 registers need to be saved.
(*p).first or p->first. In Ada and Java, p.first.