Fibonacci-in-assembly-language

Fibonacci Sequence Program in Assembly

Fibonacci sequence is a sequence of numbers where each new number is the addition of the previous to numbers. This sequence is highly mysterious because it shows up in a lot of natural phenomenons. The seeds of the sunflower are arranged in this sequence and the size of the shell spacing between a sea shells also follows this strange sequence. marketingcommunicatieplan . The following assembly code will allow you to create a Fibonacci sequence.

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
VN:F [1.9.22_1171]
Rating: 0.0/5 (0 votes cast)
If you have any question please post here