Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Using mips assembly, In this assignment, I need to display the running sum (tota

ID: 3846633 • Letter: U

Question

Using mips assembly, In this assignment, I need to display the running sum (total located on the right side of chart) of a fixed amount of 20 first fibo numbers. I got the fibo numbers running but need the running sum(total) (on the right side of the chart)..

WARNING: PLEASE DON'T answer this question if the code is not WORKING AND don't just copy and paste my code like how some chegg expert did and submit it as ANSWER....

# Compute several Fibonacci numbers and put in array, then print
      .data
fibs: .word   0 : 20        # "array" of words to contain fib values
size: .word   20            # size of "array"
##prompt: .asciiz "How many fibonacci numbers to generate ? (2 <= x <= 20)"
      .text
      la   $s0, fibs        # load address of array
      la   $s5, size        # load address of size variable
      lw   $s5, 0($s5)      # load array size
    

      li   $s2, 1           # 1 is first and second Fib. number
      add.d $f0, $f2, $f4
      sw   $s2, 0($s0)      # F[0] = 1
      sw   $s2, 4($s0)      # F[1] = F[0] = 1
      addi $s1, $s5, -2     # Counter for loop, will execute (size-2) times
loop: lw   $s3, 0($s0)      # Get value from array F[n]
      lw   $s4, 4($s0)      # Get value from array F[n+1]
      add $s2, $s3, $s4    # $t2 = F[n] + F[n+1]
      sw   $s2, 8($s0)      # Store F[n+2] = F[n] + F[n+1] in array
      addi $s0, $s0, 4      # increment address of Fib. number source
      addi $s1, $s1, -1     # decrement loop counter
      bgtz $s1, loop        # repeat if not finished yet.
      la   $a0, fibs        # first argument for print (array)
      add $a1, $zero, $s5 # second argument for print (size)
      jal print          # call print routine.
      #The program is finished.
      li   $v0, 10          # system call for exit
      syscall               # Exit!.
      
######### routine to print the numbers on one line.

      .data
space:.asciiz " "          # space to insert between numbers
cr:   .asciiz " "
head: .asciiz "The Fibonacci numbers are: "
number: .asciiz "Number"
total:.asciiz "Total"

      .text
print:add $t0, $zero, $a0 # starting address of array
      add $t1, $zero, $a1 # initialize loop counter to array size
      la   $a0, head        # load address of print heading
      li   $v0, 4           # specify Print String service
      syscall               # print heading
out: lw   $a0, 0($t0)      # load fibonacci number for syscall
      li   $v0, 1           # specify Print Integer service
      syscall               # print fibonacci number
      la   $a0, space       # load address of spacer for syscall
      li   $v0, 4           # specify Print String service
      syscall               # output string
      addi $t0, $t0, 4      # increment address
      addi $t1, $t1, -1     # decrement loop counter
      bgtz $t1, out         # repeat if not finished
      jr $ra                # return

For example, the output of the program should have first 5 numbers in the series. Fibonacci series Number total 1 2 12 6765

Explanation / Answer

# Compute several Fibonacci numbers and put in array, then print
      .data
fibs: .word   0 : 20        # "array" of words to contain fib values
size: .word   20            # size of "array"
##prompt: .asciiz "How many fibonacci numbers to generate ? (2 <= x <= 20)"
      .text
      la   $s0, fibs        # load address of array
      la   $s5, size        # load address of size variable
      lw   $s5, 0($s5)      # load array size
    

      li   $s2, 1           # 1 is first and second Fib. number
      add.d $f0, $f2, $f4
      sw   $s2, 0($s0)      # F[0] = 1
      sw   $s2, 4($s0)      # F[1] = F[0] = 1
      addi $s1, $s5, -2     # Counter for loop, will execute (size-2) times
loop: lw   $s3, 0($s0)      # Get value from array F[n]
      lw   $s4, 4($s0)      # Get value from array F[n+1]
      add $s2, $s3, $s4    # $t2 = F[n] + F[n+1]
      sw   $s2, 8($s0)      # Store F[n+2] = F[n] + F[n+1] in array
      addi $s0, $s0, 4      # increment address of Fib. number source
      addi $s1, $s1, -1     # decrement loop counter
      bgtz $s1, loop        # repeat if not finished yet.
      la   $a0, fibs        # first argument for print (array)
      add $a1, $zero, $s5 # second argument for print (size)
      jal print          # call print routine.
      #The program is finished.
      li   $v0, 10          # system call for exit
      syscall               # Exit!.
      
######### routine to print the numbers on one line.

      .data
space:.asciiz " "          # space to insert between numbers
cr:   .asciiz " "
head: .asciiz "The Fibonacci numbers are: "
number: .asciiz "Number"
total:.asciiz "Total"

      .text
print:add $t0, $zero, $a0 # starting address of array
      add $t1, $zero, $a1 # initialize loop counter to array size
      la   $a0, head        # load address of print heading
      li   $v0, 4           # specify Print String service
      syscall               # print heading
out: lw   $a0, 0($t0)      # load fibonacci number for syscall
      li   $v0, 1           # specify Print Integer service
      syscall               # print fibonacci number
      la   $a0, space       # load address of spacer for syscall
      li   $v0, 4           # specify Print String service
      syscall               # output string
      addi $t0, $t0, 4      # increment address
      addi $t1, $t1, -1     # decrement loop counter
      bgtz $t1, out         # repeat if not finished
      jr $ra                # return

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote