mips qtspim

Project Description:

the code below spits out the last 5 numbers of fibonacci. i want to store each of the values into the array with sw. then i would like to lw later on to print the values. please help!!











.data


n1: .asciiz "n" #ascii for a new line

.align 2



name: .asciiz "fibonaccinnn" #lab title and student name
.align 2

msg1: .asciiz "fibonacci result " #note the space
.align 2


msg2: .asciiz " is " #note the space
.align 2

**array: .space 20 #define the array**

.text #
.globl main #declare main to be global



main:



la $a0,name #load the ram address of "name" into $a0
li $v0,4 #system call, type 4, print a string, $a0
syscall #call the "os" to perform operation

li $t2,0 # $t2 :=0; initial value of f(n-2)
li $t1,1 # $t1 :=1; initial value of f(n-1)

li $t4,0 #index, n.

#loop is a local variable
li $t5,11 #loading immediate preset value for $t5




**la $t7,array #load address (array) into $t7**





loop: addu $t0,$t1,$t2 # f(n) = f(n-1) + f(n-2)

**#only print the last 5 numbers**
sub $t3,$t5,$t4
li $t6,5
bgt $t3,$t6,printl


la $a0,msg1 # $a0 := address of message 1
li $v0,4 #system call, type 4, print a string
syscall #call the "os"

move $a0,$t4 # $t4 contains the current value of n
li $v0,1 #system call, type 1, print an integer $a0
syscall #call the "os"

la $a0,msg2 # $a0:=address of "msg2"
li $v0,4 #system call, type 4, print a string
syscall #call the "os"

move $a0,$t0 # $a0 :=$t0, which is f(n)
li $v0,1 #system call, type 1, print an integer $a0
syscall #call the "os"


**sw $s0, 4($t7)**





la $a0,n1 # $a0 := address of "n1"
li $v0,4 #system call, type 4, print a string
syscall #call the "os"




addi $t4,1 # $t4 := $t4 + 1; increment n
move $t2,$t1 # $t2 := $t1; old f(n-2) because old f(n-1)
move $t1,$t0 # $t1 := $t0; old f(n-2) because old f(n)



beq $t5,$t4,exit #conditional check | exit







j loop # branch unconditionally to loop ($t3 != 0)

exit:
la $a0,n1 # $a0 := address of message 1
li $v0,4 #system call, type 4, print a string
syscall #call the "os"

#la $t7,array
#li $v0,1
#sw $s0, 4($t7)
#syscall


li $v0,10 #system call, type 10, standard exit
syscall #call the "os"

printl:
addi $t4,1
move $t2,$t1
move$t1,$t0
j loop
Skills Required:
Project Stats:

Price Type: Negotiable

Expired
Total Proposals: 1
1 Current viewersl
18 Total views
Project posted by:

Proposals

Proposals Reputation Price offered