Ask 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) { 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?

+2
Answers (1)
  1. 26 October, 17:59
    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 & Technology if the answers seem to be not correct or there’s no answer. Try a smart search to find answers to similar questions.
Search for Other Answers