Ask Question
Today, 14:16

Given a following C program, where M and N are constant declared with #define long P[M][N]; long Q[N][M]; long sum_element (long i, long j) { return P[i][j] + Q[j][i]; } In compiling this program, gcc generates the following assembly code: long sum_element (long i, long j) sum_element: leaq 0 (,%rdi, 8), %rdx subq %rdi, %rdx addq %rsi, %rdx leaq (%rsi,%rsi, 4), %rax addq %rax, %rdi movq Q (,%rdi, 8), %rax addq P (,%rdx, 8), %rax ret What are the values of M and N?

+5
Answers (1)
  1. Today, 14:23
    0
    Check the explanation

    Explanation:

    The first, second and third instruction together set %rdx = 3*%rdi + %rsi. The fourth and fifth instruction set %rdi = %rdi+9*%rsi.

    Now %rdi is used to address Q, while %rdx is used to address P. Note that P is addressed by column and then by row. Hence M = 3. Also Q is addressed by row and then column, hence N = 9.
Know the Answer?
Not Sure About the Answer?
Find an answer to your question ✅ “Given a following C program, where M and N are constant declared with #define long P[M][N]; long Q[N][M]; long sum_element (long i, long j) ...” in 📘 Computers and Technology if you're in doubt about the correctness of the answers or there's no answer, then try to use the smart search and find answers to the similar questions.
Search for Other Answers