Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

=+Are there shop stewards?

Answered: 1 week ago

Question

Describe Table Structures in RDMSs.

Answered: 1 week ago