Fibonacci Sequence Program in Assembly
First we load all the nesscary header files required. Marroquineria . This program works on pc spim. But if you want you want can change the header files to whatever software youre using. The main logic remains the same.
Fibonacci Sequence Program in Assembly Code
.dataspc: .asciiz " ".text.globl main
Now we initialize the constants that are required for the loops.
main: li $t0,1 li $t1,1 li $t2,9 li $t3,1
we are moving the required constants into the syscall control register. If your using AVR studio for burning a code. Skip this and just display the data on the pins directly
move $a0,$t0 li $v0,1 syscall la $a0,spc li $v0,4 syscall move $a0,$t1 li $v0,1 syscall la $a0,spc li $v0,4 syscall
Now comes the main logic. We will add the two ones. Replace the result in one register, and swap the place of the other. For example, Consider registers R10 and R11 contain the numbers 1 and 1. We add R10 and R11 and replace the R10 with R11 and the contents of R11 with the result. So we have 1 and 2 now. Again adding them gives us 3 and if we keep swapping like before we will get 2 and 3 in the registers. armband kinderen . This will start to create the sequence 1,1,2,3,5,8,13 and so on.
loop: add $t4,$t0,$t1 move $a0,$t4 li $v0,1 syscall la $a0,spc li $v0,4 syscall Move $t0,$t1 Move $t1,$t4 addi $t3,1 bne $t3,$t2,loopexit: li $v0,10 syscall