Question: Can I get help with these questions regarding MIPS and can the answers be in a regular text format? three examples are provided below. thank

Can I get help with these questions regarding MIPS and can the answers be in a regular text format? three examples are provided below. thank you!

here is the code below from the examples in text form:

# adds three values stored at 3 variables

main: lui $sp,0x7fff

ori $sp,$sp,0xfffc

lw $t0, v1

lw $t1, v2

addu $v0, $t0, $t1

lw $t0, v3

addu $v0, $v0, $t0

*done: beq $0,$0,done

v1: .word 1

v2: .word 2

v3: .word 3

# adds the first n natural numbers

main: lui $sp,0x7fff

ori $sp,$sp,0xfffc

lui $s0,0x0000

ori $s0,$s0,0x0005 # n stored here

addu $a0, $s0, $zero

jal add_nat_num

*done: beq $0,$0,done

add_nat_num: xor $t0, $t0, $t0 # set $t0 to zero. It will work as the counter

xor $v0, $v0, $v0 # set $v0 to zero. It will work as return value

beq $a0, $t0, end_fn # special case if n == 0

loop: addiu $t0, $t0, 1 # increment counter

addu $v0, $v0, $t0

bne $a0, $t0, loop

end_fn: jr $ra

# compute the factorial of n using recursive function calls

main: lui $sp,0x7fff

ori $sp,$sp,0xfffc

lui $a0,0x0000

ori $a0,$s0,0x0005 # n stored here

jal factorial

*done: beq $0,$0,done

factorial: addiu $t0, $zero,4

addiu $t1, $zero, 1

sw $ra, ($sp)

subu $sp,$sp, $t0

sw $a0,($sp)

subu $sp,$sp, $t0

bne $a0, $t1, else

move $v0, $t1

addu $sp,$sp,$t0

addu $sp, $sp, $t0

jr $ra

else: sub $a0,$a0,$t1

jal factorial

addu $sp,$sp,$t0

lw $t3, ($sp)

mul $v0, $v0, $t3

addu $sp,$sp,$t0

lw $ra, ($sp)

jr $ra

Can I get help with these questions regarding MIPS and can the

answers be in a regular text format? three examples are provided below.

thank you! here is the code below from the examples in text

form: # adds three values stored at 3 variables main: lui $sp,0x7fff

#adds three values stored at 3 variables main: lu$sp,0x7fff ori$sp,$sp, Oxfffc lw $to, v1 lw $t1, V2 addu $vo, Sto, $t1 lw $to, 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 lul $50,0x0000 ori $80,$s0,0x0005 # n stored here addu $a0,$so, Szero Jal addnat num *done: beg $0.$0,done addnat num: xor Sto, Sto, sto # set $to to zero. It will work as the counter xor Svo, $vo, $vo # set $v0 to zero. It will work as return value beg $a0,$to, end fn # special case if n == 0 loop: addiu Sto, $to, 1# increment counter addu $vo, $vo, Sto bne Sad, Sto, loop end fn: ir Sra #compute the factorial of n using recursive function calls main: lui $sp,Ox7fff or $sp,$sp, Oxfffc lul Sa0,0x0000 ori Sa0,$50,0x0005 # n stored here ial factorial *done: beg $0.50,done factorial: addiu Sto, Szero,4 addiu $t1, Szero, 1 sw Sra, ($sp) subu $sp,$sp, Sto sw $aq.($sp) subu $sp,$sp,$to bne $20, $1, else move Svo, St1 addu $sp,$sp,$to addu $sp,$sp,$to ir Sra else: sub $a0,$a0,$t1 jal factorial addu $sp,$sp,$to lw $t3,($sp) mul Svo, $vo, St3 addu $sp,$sp,$to w Sra, (Ssp) It 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

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

Sure lets work through the problems Problem 1 Factorial Using a Loop Heres how you can com... View full answer

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!