Question: using these examples with MIPS, can I get help with these problems? thanks # adds three values stored at 3 variables main: lui $sp,0x7fff ori

using these examples with MIPS, can I get help with these problems? thanks  using these examples with MIPS, can I get help with these
problems? thanks # adds three values stored at 3 variables main: lui
$sp,0x7fff ori $sp$sp, Oxfffc lw $to, vi lw $t1, V2 addu $vo,
$t0,$t1 lw Sto, v3 addu $vo, $vo, Sto *done: beg $0.50,done vi:

# adds three values stored at 3 variables main: lui $sp,0x7fff ori $sp$sp, Oxfffc lw $to, vi lw $t1, V2 addu $vo, $t0,$t1 lw Sto, v3 addu $vo, $vo, Sto *done: beg $0.50,done vi: word 1 v2 word 2 V3 word 3 # adds the first n natural numbers main: lui $sp,0x7fff ori $sp,$sp,Oxfffc lui $50,0x0000 ori $50,$s0,0x0005 # n stored here addu $a0, $so, Szero jal add_nat_num *done: beg $0.50,done add_nat_num: xor Sto, Sto, Sto # set Sto to zero. It will work as the counter xor $v0, $vo, svo # set Svo to zero. It will work as return value beg $ao, $to, end_fn # special case if n == 0 loop: addiu Sto, $t0, 1 # increment counter addu $vo, Svo, Sto bne Sao, Sto, loop end fn: je sra # compute the factorial of n using recursive function calls main: Jul Ssp.Ox7fff or $sp,$sp, Oxfffc lut Sa0,0x0000 ori. $a0,$50,0x0005 # n stored here Jal factorial *done: beg $0.50,done factorial: addiu Sto, Szero,4 addiu $t1, Szero, 1 sw $ra, ($sp) subu $sp,$sp, Sto sw Sac[$sp) subu $sp,$sp, Sto bne $ao, $1, else move Svo, $t1 addu $sp,$sp, Sto addu sp,$sp,$t0 Ic Sra else: sub Saq. Sa0,$t1 lal factorial addu $sp, Ssp.Sto lw $t3,($sp) mul Svo, $vo, St3 addu $sp,$sp,Sto w Sra,($sp) ir Sra Problem 1 Using the last example provided in the previous page, create a factorial function that work using a loop instead of a recursion. To achieve this, you need to use a counter and a loop, which is implemented using jump instructions. The second example (adding n natural numbers) uses a loop, you can use it as an example. Problem 2 Create a recursive version of the Fibonacci function. Problem 3 Create an iterative version of the Fibonacci function. Problem 4 As you probably guessed, the Fibonacci example provided in the previous page does a lot of saving retrieving of data. In particular, the cost of storing this variables is linear with respect to the number of recursive calls, which is linear with respect to the size of the number. There is an optimization that allows you to use a single stack frame for the whole function. This is called tail recursion and it reduces the cost of recursive functions from linear to constant time. I leave you this link to figure out how to create your own tail recursive function: https://stackoverflow.com/questions/310974/what-is-tail-call- optimization Problem 5 For this problem you will use an online compiler explorer at URL: https://godbolt.org/. In this website, you provide a source code and it converts it to the assembly language indicated. Be sure to change it to MIPS gcc 5.4 (this is the 32bit version of MIPS, which is simpler than the 64 version). Compile the assembly of the following program: int mainot int 419] = {5,10,13,22,16,48,13,90,31). Int sum = for (int i=0;i

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!