> For the complete documentation index, see [llms.txt](https://valineliu.gitbook.io/deuterium-wiki/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://valineliu.gitbook.io/deuterium-wiki/reading/cs-jing-dian-shu-ji/csapp-3e-homework-solution/3.-machine-level-representation-of-programs/3.65-multiple-dimension-array-ii.md).

# 3.65 Multiple Dimension Array II

★

The following code transposes the elements of an $$M\times M$$ array, where $$M$$ is a constant defined by `#define`:

```c
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;
        }
    }
}
```

When 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]`?

%rdx

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

%rax

C. What is the value of $$M$$ ?

15
