Question: The following code transposes the elements of an MM array, where M is a constant defined by #define: #define M ... void transpose( long A[M][M]

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

#define M ... void transpose( long A[M][M] ) { long i, j; for( i = 0; i  

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

.L6: movq (%rdx), %rcx # loop body starts here movq (%rax), %rsi movq %rsi, (%rdx) movq %rcx, (%rax) addq $8, %rdx # loop update code starts here addq $120, %rax cmpq %rdi, %rax jne .L6 

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

Which register holds a pointer to array element M is a constant defined by #define: #define M ... void transpose(A[i][j]?

Which register holds a pointer to array element long A[M][M] ) { long i, j; for( i = 0; iA[j][i]?

What is the value of M (in decimal)?

(PS: If you're curious, the full assembly code is:)

 transpose: leaq 120(%rdi), %r10 leaq 8(%rdi), %r9 subq $-128, %rdi movl $0, %r8d jmp .L2 .L6: movq (%rdx), %rcx movq (%rax), %rsi movq %rsi, (%rdx) movq %rcx, (%rax) addq $8, %rdx addq $120, %rax cmpq %rdi, %rax jne .L6 .L5: addq $120, %r10 addq $8, %r9 subq $-128, %rdi .L2: addq $1, %r8 cmpq $15, %r8 je .L1 testq %r8, %r8 jle .L5 movq %r9, %rax movq %r10, %rdx jmp .L6 .L1: rep ret 
MM

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!