Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Data Mining Concepts And Techniques

Authors: Jiawei Han, Micheline Kamber, Jian Pei

3rd Edition

0123814790, 9780123814791

More Books

Students also viewed these Databases questions

Question

1. What do I mean? Do I define things adequately?

Answered: 1 week ago