Question: 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

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 compq %rdi , %rdx

16 jne .L3

17 rep ; ret

18 .L4:

19 mol $0 , &eax

20 ret

Use your reverse engineering skills to determine the definitions of NR and NC.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!