		.data
prompt:		.asciiz	"input n: "
n:		.word 0
out:		.asciiz "fib(n) = "
trailer:	.asciiz "\n"
		.text
main:
		sub $sp, $sp, 12
		sw $fp, 4($sp)
		add $fp, $sp, 12
		sw $ra, 0($fp)
		sw $s0, -4($fp)
		la $a0, prompt
		li $v0, 4
		syscall
		li $v0, 5
		syscall
		move $a0, $v0
		jal fib
		move $s0, $v0
		la $a0, out
		li $v0, 4
		syscall
		move $a0, $s0
		li $v0, 1
		syscall
		la $a0, trailer
		li $v0, 4
		syscall
		lw $s0, -4($fp)
		lw $ra, 0($fp)
		lw $fp, 4($sp)
		add $sp, $sp, 12
		li $v0, 0
		jr $ra
	
fib:		sub $sp, $sp, 16
		sw $fp, 4($sp)
		add $fp, $sp, 16
		sw $ra, 0($fp)
		sw $a0, -4($fp)
		bge $a0, 2, rec_fib
		li $v0, 1
		j fib_done

rec_fib:	sub $a0, 1
		jal fib
		sw $v0, -8($fp)
		lw $a0, -4($fp)
		sub $a0, 2
		jal fib
		lw $v1, -8($fp)
		add $v0, $v0, $v1
	
fib_done:	lw $ra, 0($fp)
		lw $fp, 4($sp)
		add $sp, $sp, 16
		jr $ra
