# Sample Exercises for Quiz 3

### The Stack, Accessing Stack Variables, One-Dimensional Arrays, Multi-Dimensional Arrays, Structures, Unions [multi-dimensional arrays, structs/unions, and arrays of structs will not be on Quiz 3 but will be on the Midterm]

```Review the load/store instructions, alignment restrictions,
instructions to allocate local variables on the stack.

What are some of the reasons why we have to use the runtime Stack for local
variables (as opposed to just mapping all local variables to registers)?

Draw what the following local variable definitions would look like on the Stack.
Write the appropriate instructions to allocate these local
variables on the Stack. Write ARM assembly statements to store the initial
values in each local variable.  Write ARM assembly statements to
access/read and write each local variable (for example, passing each local
variable as a parameter to a function and also to take the return value from
a function store it in each local stack variable).

int   a = 17;
short b = 4000;
char  c = 'd';
unsigned short d = 5000;
char  e = '7';
long  f = 0x12345678;

----------------------

Draw what the following local variable definitions would look like on the Stack.

Write the appropriate instructions to allocate these local variables on the Stack.

Write ARM assembly statements to perform the accompanying C statements.
Write 2 versions of the loop: one using standard indexing (left) and another
using a traversal pointer (right).

Write a version where local variables i and ptr are mapped to local
registers and another version where these local variables are not mapped to
local registers but are allocated on the Stack just like the array.

#define A_SIZE 7			    #define A_SIZE 7

int i;				    int i;
int a[A_SIZE];			    int a[A_SIZE];
int *ptr = a;

for ( i = 0; i < A_SIZE; ++i ) {	    for ( i = 0; i < A_SIZE; ++i ) {
a[i] = i;			       *ptr = i;
printf( "%d\n", a[i] );		       printf( "%d\n", *ptr );
}					       ++ptr;
}

----------------------

Draw what the following local variable definition would look like on the Stack.

Write the appropriate save instruction to allocate this local
variable on the Stack.

Write ARM assembly statements to perform the accompanying C statements.

struct foo {
long  a;
short b;
char  c;
int   d;
char  e;
int   f;
short g;
} fubar;

fubar.a = -5005;
fubar.b = -33;
fubar.c = 'C';
fubar.d = 75;
fubar.e = '3';
fubar.f = 23;
fubar.g = 0;

fubar.a = fubar.g;
fubar.c = fubar.e;
fubar.b = fubar.g;

----------------------

What if the above struct definition was changed to be a union?

----------------------

Operator Precedence
Operator Associativity
Order of Evaluation of Operands

Rt.-Lt. Rule

modifiable lval / lval / rval
- The 4 C operators that evaluate to a modifiable lval

Review multi-dimensional arrays and arrays of structures.
```