Admin access
=======Q1(W1 2021 Mt1)=======
Global Variables and Arrays [10 marks]
Consider the following global variable declarations. Treat each subquestion separately;
i.e., your answer for any of them must be correct on its own. Use the labels to refer to
static values. No comments needed.
int *a;
int b[5];
a) [2.5] Give the assembly code that places the value of expression a[2] into r0.
b) [2.5] Give the assembly code that places the value of expression b[2] into r0.
c) [2.5] Give the assembly code that places the number 2 into b[2].
d) [2.5] Give the assembly code that places the value of the expression &a[2] into r0.
========Q2(Winter 2018, Term 2)========
Consider the following global variable declarations.
int a[4] = (int[4]){5, 4, 3, 2};
int b[3] = (int[3]){6, 7, 8};
int* c;
Assume that the address of a is 0x1000, the address of b is 0x2000, and the address
of c is 0x3000. Now, consider the the execution of the following additional code.
c = &a[3];
b[*c] = a[1];
c = (b+1);
*c = *c + 1;
*c = *c + 1;
a[3] = c[1];
Indicate the value of each of the following expressions (i.e., the values of a, b, and c) below by checking Unchanged if the execution does not change the value or by entering its new value in the space provided. Assuming that int’s are 4-bytes long. Answer these questions about the value of these variables following the execution of this code.
a[0]: Unchanged_ or Changed to Value ____________
a[1]: Unchanged_ or Changed to Value ____________
a[2]: Unchanged_ or Changed to Value ____________
a[3]: Unchanged_ or Changed to Value ____________
b[0]: Unchanged_ or Changed to Value ____________
b[1]: Unchanged_ or Changed to Value ____________
b[2]: Unchanged_ or Changed to Value ____________
c : Unchanged_ or Changed to Value ____________
========Q3(Winter 2021, Term 1)========
========Q4(Winter 2021, Term 1)========