Write assembly languageMIPS code please Following Objecti

Write assembly language(MIPS) code, please.

Following:

###########################################################

#
# Objective:
# Learning recursive design in assembly by implementing Fibonacci series.
#
# Description:
# Main will initialize registers $t0 and $t1 to 0 and 10 respectively
# and for all values in range 0...10, it will call subprogram fibonacci($t0).
#
# Note:
# Implement the main and fibonacci subprogram, then run the code to print
# Fibonacci series of 10 elements. Checkout with your TA.
#
# High-level design:
# main:
# $t0 <-- counter (initialize to 0)
# $t1 <-- number of terms in series (initialize to 10)
#
# while ($t0 < $t1) {
# print fibonacci($t0)
#
# $t0 <-- $t0 + 1
# }
#
# halt
#
# Sample run:
# Fibonacci series using recursion (modify $t1 to change number of terms): 0, 1, 2, 3, 5, 8, 13, 21, 34, 55,
#
###########################################################
# Register Usage
# $t0 Holds value 0 (initialized to zero)
# $t1 Holds constant value 10
###########################################################
.data
prompt_p: .asciiz \"Fibonacci series using recursion (modify $t1 to change number of terms): \"
space_p: .asciiz \", \"
###########################################################
.text
main:
li $t0, 0 # initialize counter to 0
li $t1, 10 # initialize number of terms to 10

li $v0, 4 # print Fibonacci series is:
la $a0, prompt_p
syscall

loop:
bge $t0, $t1, mainEnd # if counter == 10 the branch to mainEnd

# call: result <-- fibonacci($t0) and print result
# TODO


addi $t0, $t0, 1 # increment counter by 1

b loop # branch unconditionally back to beginning of the loop

mainEnd:
li $v0, 10 # halt
syscall
###########################################################
# fibonacci subprogram
#
# subprogram description:
# this subprogram receives as argument IN an integer value and if
# the integer is less than or equal to 2 then it returns the value in $sp + 4.
# otherwise, it recursively calls a = fibonacci(value - 1) and
# b = fibonacci(value - 2) and subprogram returns a + b
#
# Algorithm:
# fibonacci(int value) {
# if(term <= 2) {
# return term;
# }
#
# return fibonacci(value - 1) + fibonacci(value - 2);
# }
#
###########################################################
# Arguments IN and OUT of subprogram
# $a0
# $a1
# $a2
# $a3
# $v0
# $v1
# $sp # Holds argument IN (input value)
# $sp+4 # Holds argument OUT or fibonacci(value)
# $sp+8
# $sp+12
###########################################################
# Register Usage
# $t0 Holds value (or the term number)
# $t1 Holds constant value 2
# $t2 Holds fibonacci(value - 1)
# $t3 Holds fibonacci(value - 2)
# $t4
# $t5
# $t6
# $t7
# $t8
# $t9 temporarily
###########################################################
.data
###########################################################
.text
fibonacci:
# TODO


fibonacci_end:


jr $ra # jump back to main
###########################################################

Solution

Here is your program :

Write assembly language(MIPS) code, please. Following: ########################################################### # # Objective: # Learning recursive design in
Write assembly language(MIPS) code, please. Following: ########################################################### # # Objective: # Learning recursive design in
Write assembly language(MIPS) code, please. Following: ########################################################### # # Objective: # Learning recursive design in

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site