Question: 1 ) Recursion Write an assembly function dumb ( a , b ) that takes two unsigned integer arguments and implements this recursive calculation (

1)
Recursion
Write an assembly function dumb(a, b) that takes two unsigned integer arguments and implements this recursive calculation (that's called "dumb" because it does a dumb calculation that makes no sense, but that's the task):
def dumb(a, b):
if a ==0:
return b +1
elif b ==0:
return a
else:
return a + a + b + dumb(a -1, b -1)
You must use the stack to store the a and b values across the recursive call.
pass these tests:
printf("dumb(0,5)==6==%li
", dumb(0,5));
printf("dumb(7,0)==7==%li
", dumb(7,0));
printf("dumb(3,5)==27==%li
", dumb(3,5));
printf("dumb(17,63)==1288==%li
", dumb(17,63));
2)Unsigned Overflow
Write an assembly function largest_power_unsigned that takes an unsigned integer as its argument and returns the largest power of that number that's representable as a 64-bit unsigned integer.
In order to find that value, you need to repeatedly multiply by
until you see an unsigned overflow and return the value before you saw the overflow.
The value you return p
should be a power of n
, so n^i =p
for some i
, such that p <2^64
and np >=2^64
.(But you can't detect it with math: you need to calculate and watch the carry flag.)
so it passes the tests:
printf("largest_power_unsigned(3)==12157665459056928801==%lu
", largest_power_unsigned(3));
printf("largest_power_unsigned(7)==3909821048582988049==%lu
", largest_power_unsigned(7));

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!