Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

***Do No Copy from chegg*** Using RISC_V and RARS Computer architecture 64 bit enable answers the follow questions given this code in RISC-V using RARS

***Do No Copy from chegg***

Using RISC_V and RARS Computer architecture

64 bit enable

answers the follow questions given this code in RISC-V using RARS

# Example of recursion in RISC-V with Factorial #############################################

.data doneString: .asciz " Done."

.text

li a0, 5 # loading n into the first argument register (a0) jal fact # jumping and linking to the fact procedure li a7, 1 # result of fact is already in a0 ecall # print integer ecall (1) j exit # if we do NOT do this, the code will simply fall through to fact again

fact: addi sp, sp, -16 # adjust stack for 2 items sd ra, 8(sp) # save return address sd a0, 0(sp) # save argument addi t0, a0, -1 # subtract 1 from argument bge t0, zero, L1 # if n >= 0, go to L1 li a0, 1 # else, set return value to 1 addi sp, sp, 16 # pop 2 items from stack jr ra # and return L1: addi a0, a0, -1 # if we're here, n was >= 0, haven't reached base case jal fact # recursive call mv t0, a0 # move result of fact(n-1) to t0 ld a0, 0(sp) # restore original n to a0 ld ra, 8(sp) # and return address to ra addi sp, sp, 16 # pop 2 items from stack mul a0, a0, t0 # multiply to get result jr ra # and return exit: li a7, 4 # load ecall #4 (print string) la a0, doneString # load the address of doneString (see .data section) ecall # print doneString to the console li a7, 10 # load ecall #10 (exit) ecall # .....and exit.

For the following questions, used the example assembly code using the RARS simulator. 11. [5] By the end of the program, how many different return addresses have been pushed on the stack (when n = 5)? 12. [5] What is the original value of sp? What is the lowest value (when n = 5)? How many variables are stored on the stack each iteration? 13. [10] Once the base case is reached, what is the actual sequence of values (in hex) in the a0 register? When do all of the multiplications actually take place? 14. [10] As written, what is the largest value for n that the code can correctly compute? What is the limiting instruction? How would you re-write the code to increase the maximum n it can correctly compute? What would the largest possible n be in that case?

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_2

Step: 3

blur-text-image_3

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

Machine Learning And Knowledge Discovery In Databases European Conference Ecml Pkdd 2019 Wurzburg Germany September 16 20 2019 Proceedings Part 2 Lnai 11907

Authors: Ulf Brefeld ,Elisa Fromont ,Andreas Hotho ,Arno Knobbe ,Marloes Maathuis ,Celine Robardet

1st Edition

3030461467, 978-3030461461

More Books

Students also viewed these Databases questions