00:01
Hello student, here we have to convert the given c or c+ + code into the risc -v assembly which is rv321.
00:08
So first save the caller register array on the stack.
00:12
Then check if the input parameter n is equal to 0 or 1.
00:16
If it is, the function returns 0 or 1 respectively.
00:20
Otherwise the function recursive call itself with n -2 and n -1 as argument and adds the result of the recursive call and returns the result.
00:28
So this is the way we perform r answer in the fibonacci series.
00:34
So here i have written the output is like this.
00:40
So here fib0 and fib1 are the two labels used to implement the special cases where n is equal to 0 or 1.
00:48
So with the label we can handle these special case if 0 or 1.
00:53
So here the function name is r underscore fibonacci.
00:56
So i have written r underscore fibonacci.
00:59
Save the call saved register on the stack.
01:02
So we are doing with the help of a stack.
01:05
So we have to save the caller saved register.
01:09
So here addi means add immediately.
01:11
Sp means stack pointer.
01:13
So here with the, this is a destination stack pointer.
01:17
This is a current stack pointer.
01:18
In the current stack pointer we will subtract the 4 byte and this is given to the destination.
01:24
So here it is a way of allocating the local values.
01:28
Now sw store a word, ra is a register which we are taking as a register and here we are sending 0 as a stack pointer to the ra.
01:40
Check if n is equal to 0 or 1.
01:42
So now our task is to check if n is equal to 0 or 1.
01:46
So here branch if equal to a0.
01:50
So here a0 will be branching will be done.
01:55
Branch if a0 is equal to 0 then label where to branch label fib0.
02:04
So here fib0 is a label.
02:07
Here we will do the branching if this condition satisfied if a0 is equal to 0.
02:15
Then here return 0 if n is equal to 0.
02:19
So here we will return 0 if it is equal to 0 add i, add immediately a0 0 0.
02:28
So here 0 will be added immediately to the a0 registers.
02:34
So this is the label for the fib0 and here the label for the fib1.
02:40
If a0 is equal to 1 then we will branch to the label fib1...