Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

/* Recursive popcount */ long pcount_r(unsigned long x) { if (x == 0) return 0; else return (x & 1) + pcount_r(x >> 1); }

image text in transcribedimage text in transcribed

/* Recursive popcount */ long pcount_r(unsigned long x) { if (x == 0) return 0; else return (x & 1) + pcount_r(x >> 1); } pcount_r: movl $0, $eax testa frdi, $rdi je .L6 pusha frbx mova frdi, &rbx andi $1, %ebx shra %rdi call pcountur adda rbx, frax popa %rbx .L6: rep; ret # if x==0 # done # save $rbx # x -> 8 rbx # x & 1 # x >> 1 # recurse # retval # restore rbx Problem 3. This problem considers the growth of the stack in the execution of a recursive function. Consider the recursive version of the "popcount" function (pcount.r()), as described in Lecture L10 (beginning on slide 6). Suppose that function is called with actual parameter 0x00000012, from a point where register %rbx contains 0x0000ffff, and where the address of the next instruction is Oxfff60548. Assume the address of the (recursive) call instruction is 0xffff703000, and it is a three-byte instruction. a. Including that original invocation, what is the maximum number of frames for pcounts that will be on the stack as a result? b. Draw a diagram showing the contents of the stack at the point of maximum depth of recursion. Include the value of all the items pushed onto the stack for each invocation. /* Recursive popcount */ long pcount_r(unsigned long x) { if (x == 0) return 0; else return (x & 1) + pcount_r(x >> 1); } pcount_r: movl $0, $eax testa frdi, $rdi je .L6 pusha frbx mova frdi, &rbx andi $1, %ebx shra %rdi call pcountur adda rbx, frax popa %rbx .L6: rep; ret # if x==0 # done # save $rbx # x -> 8 rbx # x & 1 # x >> 1 # recurse # retval # restore rbx Problem 3. This problem considers the growth of the stack in the execution of a recursive function. Consider the recursive version of the "popcount" function (pcount.r()), as described in Lecture L10 (beginning on slide 6). Suppose that function is called with actual parameter 0x00000012, from a point where register %rbx contains 0x0000ffff, and where the address of the next instruction is Oxfff60548. Assume the address of the (recursive) call instruction is 0xffff703000, and it is a three-byte instruction. a. Including that original invocation, what is the maximum number of frames for pcounts that will be on the stack as a result? b. Draw a diagram showing the contents of the stack at the point of maximum depth of recursion. Include the value of all the items pushed onto the stack for each invocation

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

Datacasting How To Stream Databases Over The Internet

Authors: Jessica Keyes

1st Edition

007034678X, 978-0070346789

Students also viewed these Databases questions

Question

What are the qualities to look for in a prospective franchisee?

Answered: 1 week ago