Chapter 8: Intermediate Code Generation

Example

. Let A be a 10x20 array therefore, n 1 = 10 and n 2 = 20 and assume w = 4

. code to access A[y,z] is

t 1 = y * 20

t 1 = t 1 + z

t2 = 4 * t 1

t 3 =A-84 {((low1 Xn2 )+low2 )Xw)=(1*20+1)*4=84}

t4 = t2 + t 3

x = t 4

Let A be a 10x20 array

n1 = 10 and n2 = 20

Assume width of the type stored in the array is 4. The three address code to access A[y,z] is

t1 = y * 20

t1 = t1 + z

t2 = 4 *t1

t3 =base A -84 {((low 1 *n2)+low 2 )*w)=(1*20+1)*4=84}

t4 =t2 +t3

x = t4