Consider the following source code where NR and NC are macro
Consider the following source code, where NR and NC are macro expressions declared with #define that compute the dimensions of array A in terms of parameter n. This code computes the sum of the elements of column j of the array.
1 long sum_col(long n, long A[NR(n)][NC(n)], long j) {
2 long i;
3 long result = 0;
4 for (i = 0; i < NR(n); i++)
5 result += A[i][j];
6 return result;
7 }
In compiling this program, gcc generates the following assembly code: long sum_col(long n, long A[NR(n)][NC(n)], long j) n in %rdi, A in %rsi, j in %rdx
1 sum_col:
2 leaq 1(,%rdi,4), %r8
3 leaq (%rdi,%rdi,2), %rax
4 movq %rax, %rdi
5 testq %rax, %rax
6 jle .L4
7 salq $3, %r8
8 leaq (%rsi,%rdx,8), %rcx
9 movl $0, %eax
10 movl $0, %edx
11 .L3:
12 addq (%rcx), %rax
13 addq $1, %rdx
14 addq %r8, %rcx
15 cmpq %rdi, %rdx
16 jne .L3
17 rep; ret
18 .L4:
19 movl $0, %eax
20 ret
Use your reverse engineering skills to determine the definitions of NR and NC in terms of n. It would be extremely helpful if you could describe how you got the values. Thanks so much!
Solution
Please let me know if you need more information:-
=================================================
As my analysis the following will be the macro definitions:-
#define NR(R) ((R)) ---> it will return the numner of rows based on n value
 #define NC(C) ((C)) ---> it will return the number of columns based on n value
===============================================
Thanks


