Answered step by step
Verified Expert Solution
Link Copied!

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 image text in transcribedMM 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 image text in transcribedA[i][j]?

Which register holds a pointer to array element image text in transcribedA[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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Systems Design Implementation And Management

Authors: Carlos Coronel, Steven Morris

14th Edition

978-0357673034

Students also viewed these Databases questions