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

Need help with LC 2200 project !================================================

ID: 3662294 • Letter: N

Question

Need help with LC 2200 project

!============================================================
! CS-2200 Homework 1
!
! Please do not change mains functionality,
! except to change the argument for fibonacci or to meet your
! calling convention
!============================================================

main: la $sp, stack               ! load address of stack label into $sp
noop ! FIXME: load desired value of the stack
! (defined at the label below) into $sp
la $at, fibonacci   ! load address of fibonacci label into $at
addi $a0, $zero, 8    ! $a0 = 8, the fibonacci argument
jalr $at, $ra               ! jump to fibonacci, set $ra to return addr
halt                       ! when we return, just halt


zeroDone:   addi $a0, $zero, 0       ! fib(0) = 0
           beq $zero, $zero, eval        ! proceeed to finish

oneDone:   addi $a0, $zero, 1           ! fib(1) = 1
           beq $zero, $zero, eval        ! proceed to finish

eval:


fibonacci:
#            beq $t0, $t2, continue       ! fp already set
           add $fp, $sp, $zero        ! set fp to sp
#            sw $ra, 0($fp)               ! push ra

           beq $a0, $zero, zeroDone   ! Fib number is a 0
           addi $t1, $zero, 1           ! Make a temp "one" register
           beq $a0, $t1, oneDone       ! Fib number is a 1
           addi $a1, $a0, -1           ! a1 = a0 - 1
           addi $a2, $a0, -2           ! a2 = a0 - 2

           !ADDING ARGS ONTO STACK
           sw $a1, 0($fp)               ! Adding a1 to the stack
           sw $a2, 1($fp)               ! Adding a2 to the stack

           sw $v0, 2($fp)               ! Add the return value onto the stack
           sw $ra, 3($fp)               ! Add the return addr onto the stack
           sw $fp, 4($fp)               ! Save the old frame pointer

           addi $fp, $fp, 5           ! update frame pointer
           jalr $at, $ra               ! Recursive call to the numbers on stack

recursiveFib:
           ld
          

stack:   .word 0x4000               ! the stack begins here


!fibonacci(n) = fibonacci(n - 1) + fibonacci(n - 2)
!fibonacci(0) = 0, and fibonacci(1) = 1

Explanation / Answer

fibonacci:
   beq $t0 ,$t2 done ! t0,t2 define here

   add $fp, $sp $t0 ! $fp and $sp add two varaibles and place it into $t0

   sw $ra ,0($fp) ! store into memory

   beg $a0 $zero done ! zero placed into $a0

   add $t1,$a0 1 ! make temp as "one " register

   beg $a0 $t1 done ! t1 value placed into $a0

the above lines are modified as per the logic,so place these lines to your LC 2200 Project..

I am not change any main function, so you need to change as per cs 2200 , and stack code.

There is no problem with the sw code format. so as per requirement changes are happened.