Question: This is question 3.65 (pg 317) from Book: Computer Systems: A Programmers Perspective (3rd Edition): The following code transposes the elements of an M M

This is question 3.65 (pg 317) from Book: Computer Systems: A Programmers Perspective (3rd Edition):

The following code transposes the elements of an M M array, where M is a constant by #define:

void transpose(long A[M] [M] {

long i, j;

for (i = 0; i < M; i++)

for (j = 0; j < i; j++) {

long t = A [i] [j];

A [i] [j] = A [j] [i];

A [j] [i] = t;

}

}

Then compiled with optimization level -O1, gcc generates the following code for the inner loop of the function:

.L6

movq (%rdx), %rcx

movq (%rax, %rsi

movq %rsi, (%rdx)

movq %rcx, (%rax)

addq %8, %rdx

addq $120, %rax

cmpq %rdi, %rax

jne .L6

We can see that GCC has converted the array indexing to pointer code.

A. Which register holds a pointer to array element A [i] [j] ?

B. Which register holds a pointer to array element A [j] [i] ?

C. What is the value of M ?

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!