In this reading, you’ll learn about how arrays are organized in x86-64 and how they can be accessed. You will also see the deep relationship between arrays and pointers in C, by seeing how closely related they are at the assembly level.
In a few lectures we will see how the organization of arrays can play a huge role in program performance. For now it will suffice to understand the basic mechanisms involved x86-64 arrays and pointers.
Sections 3.8.0 - 3.8.3 (pp. 255-260) from the course textbook; and the intro to Section 5 of this webpage (i.e. everything before Section 5.1).
Each student will be responsible for learning and demonstrating proficiency in the following objectives PRIOR to the class meeting. The reading quiz will test these objectives.
The following objectives should be mastered by each student DURING and FOLLOWING the class session through active work and practice.
These exercises are geared towards mastering the BASIC learning objectives listed above. You are expected to submit them before class and it is highly recommended that you complete them before attempting the reading quiz.
Assume that you have an array named my_array
and an assignment to the ith element of that array as follows.
my_array[i] = 5;
Assuming that the starting address of my_array
is in %r10
and i is stored in %r13
, write the correct x86-64 instruction to perform this assignment, assuming my_array
is of the following types.
char
:int
:long int
:Consider the following C code.
short int *my_short_arr = calloc(4, sizeof(short int));
my_short_arr[0] = 10;
my_short_arr[1] = 20;
my_short_arr[2] = 30;
my_short_arr[3] = 40;
Assuming that my_short_arr
starts at address 0x100, fill in the following table to give the type (e.g. short int
) and value (e.g. 0x104 or 30) of the following expressions.
Express | Type | Value |
&my_short_arr[1] | ||
my_short_arr[2] | ||
my_short_arr+3 |
Consider the following 2D array/matrix.
int my_matrix[5][20];
Assuming that my_matrix
starts at address 0x300, what is the address of the following elements of the matrix?
my_matrix[0][1]
my_matrix[1][0]
my_matrix[3][12]