Presentation is loading. Please wait.

Presentation is loading. Please wait.

Variable Storage Memory Locations (Logical) Variable Classes Stack

Similar presentations


Presentation on theme: "Variable Storage Memory Locations (Logical) Variable Classes Stack"— Presentation transcript:

1 Variable Storage Memory Locations (Logical) Variable Classes Stack
Heap Program Code Register Variable Classes Automatic (locals) Parameters Globals

2 Variable Types Scalars Arrays Structs Unions Objects ?

3 Row Major Array Storage
char A[20][15][10]; 1000 A[0][0][0] . . . 1150 A[1][0][0] 1160 A[1][1][0] 1161 A[1][1][1] 3999 A[19][14][9]

4 Column Major Array Storage
char A[20][15][10]; 1000 A[0][0][0] 1001 A[1][0][0] . . . 1021 A[1][1][0] 1321 A[1][1][1] 3999 A[19][14][9]

5 OR (Row Major) char A[20][15][10]; 3999 A[0][0][0] . . . 3849
3839 A[1][1][0] 3838 A[1][1][1] 1000 A[19][14][9]

6 Array Declaration Algorithm
Dimension Node { int min; int max; int size; }

7 Declaration Algorithm (2)
Doubly linked list of dimension nodes Pass 1 – while parsing Build linked list from left to right Insert min, max Size = size of an element Append node to end of list min = max = size = 1

8 Declaration Algorithm (3) Pass 2
Traverse list from tail to head For each node, n, going “right” to “left” Factor = n.max – n.min + 1 For each node, m, right to left starting with n m.size = m.size * factor For each node, n, going left to right N->right->max = max; N->right->min = min Delete first element of list

9 Array Declaration (Row Major)
int weight[ ][1..12][1..31]; list of “dimension” nodes int min, max, size size of element of this dimension 1448 124 4

10 Array Offset (Row Major)
Traverse list summing (max-min) * size int weight[ ][1..12][1..31]; x = [2002][5][31] ( ) * (5-1) * (31-1) * 4 1448 124 4

11 Your Turn Assume “Show” A’s dimension list
int A[10][20][30]; Row major order “Show” A’s dimension list Show hypothetical 3-addr code for X = A[2][3][4] ; A[3][4][5] = 9

12 Your Turn 2 Assume “Show” A’s dimension list
int A[10][20][30]; Column major order “Show” A’s dimension list Show hypothetical 3-addr code for X = A[2][3][4] ; A[3][4][5] = 9


Download ppt "Variable Storage Memory Locations (Logical) Variable Classes Stack"

Similar presentations


Ads by Google