# Compute the first twelve Fibonacci numbers and put in array, then print. This is an example from a Web site, commented and modified by John Cole. And this comment is way too long. # .data fibs: .word 0 : 12 # "array" of 12 words to contain fib values size: .word 12 # size of "array" # Start of code. .text la $t0, fibs # load address of array la $t5, size lw $t5, 0($t5) # load array size li $t2, 1 # Load $t2 with 1 sw $t2, 0($t0) sw $t2, 4($t0) addi $t1, $t5, -2 #Subtract 2 from counter # Loop for computing numbers. compute: lw $t3, 0($t0) # Get value from array F[n] lw $t4, 4($t0) # Get value from array F[n+1] add $t2, $t3, $t4 sw $t2, 8($t0) addi $t0, $t0, 4 # increment address of Fib. number source addi $t1, $t1, -1 # decrement $t1 blez $t1,comp1 # Exit if done b compute comp1: la $a0, fibs # first argument for print (array) add $a1, $zero, $t5 # second argument for print (size) jal print # call print routine. li $v0, 10 # system call for exit syscall ######### routine to print the numbers on one line. .data space:.asciiz " " # space to insert between numbers head: .asciiz "The Fibonacci numbers are:\n" .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 syscall print5: 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 syscall addi $t0, $t0, 4 # increment address addi $t1, $t1, -1 # decrement loop counter bgtz $t1, print5 # repeat if not finished jr $ra # return