main: la $a0, prompt .data prompt: .asciiz "Number to compute fib of:" .text li $v0, 51 syscall addiu $sp, $sp, -4 sw $a0, 0($sp) jal fib lw $a0, 0($sp) sw $v0, 0($sp) la $a1, output2 jal int2str la $a0, output1 .data output1: .ascii "The value of fib(" output2: .space 12 output3: .asciiz ") is " .text lw $a1, 0($sp) li $v0, 56 syscall addiu $sp, $sp, 4 li $v0, 10 syscall fib: addiu $sp, $sp, -8 sw $ra, 0($sp) sw $a0, 4($sp) slti $t0, $a0, 2 bne $t0, $zero, baseCase addi $a0, $a0, -1 jal fib lw $a0, 4($sp) sw $v0, 4($sp) addi $a0, $a0, -2 jal fib lw $t0, 4($sp) add $v0, $v0, $t0 j return baseCase: li $v0, 1 return: lw $ra, 0($sp) addiu $sp, $sp, 8 jr $ra int2str: # takes as arguments # $a0 an integer to convert # $a1 the memory address for the result # and converts the integer to a string move $t1, $a1 # $t1 is the left-hand finger main_int2str_loop: rem $t0, $a0, 10 addi $t0, $t0, 48 sb $t0, 0($a1) addiu $a1, $a1, 1 div $a0, $a0, 10 bne $a0, $zero, main_int2str_loop sb $0, 0($a1) addiu $a1, $a1, -1 # $a1 is the right-hand finger int2str_reverse_loop: sltu $t2, $t1, $a1 # a value of 1 means we should keep going beq $t2, $zero, int2str_done # we know the left finger is still to the left of the right finger lb $t2, 0($t1) # $t2 was the byte on the left lb $t3, 0($a1) # and $t3 was on the right sb $t2, 0($a1) sb $t3, 0($t1) # now they are swapped addiu $a1, $a1, -1 addiu $t1, $t1, 1 j int2str_reverse_loop int2str_done: jr $ra strcat: # takes as arguments ... and concatenates the strings la $t0, output1 la $t1, output3 .data output4: .space 12 .text la $t2, output4 lb $t3, 0($t0) sb $t3, 0($t2) addiu $t0, $t0, 1 addiu $t2, $t2, 1