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

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

/* 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

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!