Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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 MM array, where M is a constant defined by #define:
#define M ... void transpose( long A[M][M] ) { long i, j; for( i = 0; iWhen 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 .L6We can see that gcc has converted the array indexing to pointer code.
Which register holds a pointer to array element A[i][j]?
Which register holds a pointer to array element A[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 retMM
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started