Ask Question
28 April, 18:21

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?

+4
Answers (1)
  1. 28 April, 18:46
    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?
Get 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 & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers