Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 4. Note: For this problem you will need to read and understand Section 3.7 of your text, especially 3.7.4 through 3.7.6. Consider this recursive

image text in transcribedimage text in transcribed

Problem 4. Note: For this problem you will need to read and understand Section 3.7 of your text, especially 3.7.4 through 3.7.6. Consider this recursive version of the "popcount" function, which returns the number of 1 bits in its argument. int recpopcount (unsigned long n){ if (n==0) return 0; !=0/ int temp = recpopcount (n>>1); return temp +(n&1); As described in Section 3.7.6, recursive functions have to stash values normally stored in registers on the stack. The code above generates machine code (via gcc -S -0g recpopcount.c; extraneous assembler directives have been removed). Recall that the first argument is passed in % rdi, and the return value will be in \%eax when the final ret is executed. a. The value of n (i.e., the value in \%rdi) is used after the recursive call returns. Where is it saved before the call (what instruction)? b. Suppose the function is called with the argument 7 , and suppose that at the time of that call the register \%rbx contains 100. Draw a diagram showing the contents of the stack immediately after that call, assuming the address of the instruction after the call to recpopcount is 0x555500a6. Draw the stack with the "top" of the stack (i.e., the quadword containing the return address) at the bottom. (The instructor will give an example in class or on the assignment page.) c. Draw another diagram showing the stack contents immediately after the first recursive call. Your diagram should show everything from the previous part, plus anything pushed on the stack after that initial call. d. Draw another diagram showing the stack contents (including the previous parts), immediately after the last recursive call. Again, show anything pushed on the stack in the meantime

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

Step: 3

blur-text-image

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

Genomes Browsers And Databases Data Mining Tools For Integrated Genomic Databases

Authors: Peter Schattner

1st Edition

0521711320, 978-0521711326

More Books

Students also viewed these Databases questions

Question

What magazine and ads did you choose to examine?

Answered: 1 week ago