Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write a program to populate an array with Fibonacci numbers. The Fibonacci sequence begins with 0 and then 1 , each following number is the
Write a program to populate an array with Fibonacci numbers. The Fibonacci sequence begins with and then each following number is
the sum of the previous two numbers. Ex: Assume the size of the array is always at least Use the button under the
Registers display to store the size of an integer array in and the address of the first element of the array in the memory in
Ex: If and are initialized in the simulator as and the data memory starting at address will contain: this is what i have right now but it's not working not sure what i am doing wrong # Initialize array size and address
lw xx # Load the size of the array into x
lw xx # Load the address of the first element into x
# Handle the base cases
addi t x # Fib
sw tx # Store the first Fibonacci number
addi t x # Fib
sw tx # Store the second Fibonacci number
# Loop to calculate and store the rest of the Fibonacci numbers
addi t x # Start from the third element index
addi t x # Initialize Fibi
addi t x # Initialize Fibi
fibloop:
add t t t # Calculate Fibi Fibi Fibi
sw tx # Store Fibi in the array
# Move to the next Fibonacci numbers for the next iteration
add t x t # Fibi becomes Fibi
add t x t # Fibi becomes Fibi
addi x x # Move to the next element in the array
addi t t # Increment the index
blt t x fibloop # Continue the loop until the array is filled
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started