The C function funsum below takes three arguments -- an integer val and two function pointers...

Free

70.2K

Verified Solution

Question

Programming

The C function funsum below takes three arguments -- an integerval and two function pointers to functions f and g, respectively. fand g both take an integer argument and return an integer result.The function funsum applies f to val, applies g to val, and returnsthe sum of the two results. Translate to RISC-V following RISC-Vregister conventions. Note that you do not know, nor do you need toknow, what f and g do, nor do you know what registers f and guse.

long long int funsum(long long int val, long long int (*f) (longlong int), long long int (*g) (long long int))

{

return(f(val) + g(val));

}

Answer & Explanation Solved by verified expert
3.6 Ratings (622 Votes)

Answer : Given data

An integer val and two function pointers to functions f and g, respectively.

Translation to RISC-V :

funsum:

        addi    sp,sp,-64

        sd      ra,56(sp)

        sd      s0,48(sp)

        sd      s1,40(sp)

        addi    s0,sp,64

        sd      a0,-40(s0)

        sd      a1,-48(s0)

        sd      a2,-56(s0)

        ld      a5,-48(s0)

        ld      a0,-40(s0)

        jalr    a5

        mv      s1,a0

        ld      a5,-56(s0)

        ld      a0,-40(s0)

        jalr    a5

        mv      a5,a0

        add     a5,s1,a5

        mv      a0,a5

        ld      ra,56(sp)

        ld      s0,48(sp)

        ld      s1,40(sp)

        addi    sp,sp,64

        jr      ra

______________THE END___________________


Get Answers to Unlimited Questions

Join us to gain access to millions of questions and expert answers. Enjoy exclusive benefits tailored just for you!

Membership Benefits:
  • Unlimited Question Access with detailed Answers
  • Zin AI - 3 Million Words
  • 10 Dall-E 3 Images
  • 20 Plot Generations
  • Conversation with Dialogue Memory
  • No Ads, Ever!
  • Access to Our Best AI Platform: Flex AI - Your personal assistant for all your inquiries!
Become a Member

Other questions asked by students