Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .equ localSize, -16
- .equ fib, -8
- result:
- .string "The 14th Fibonacci number is: %d\n"
- #input:
- #.string "Enter your n value: "
- #.equ inputSz, 19
- .text
- .global main
- .type main, @function
- main:
- pushq %rbp
- movq %rsp, %rbp
- addq $localSize, %rsp
- movl $14, %edi
- call Fibonacci
- movl %eax, %esi
- leaq result(%rip), %rdi
- movl $0, %eax
- call printf@PLT # PLT program location table
- subq $localSize, %rsp
- movq %rsp, %rbp
- popq %rbp
- ret
- Fibonacci: #main function
- pushq %rbp
- movq %rsp, %rbp
- addq $localSize, %rsp #stack space yo
- cmpl $1, %edi #base case comparison
- je baseFib1
- cmpl $0, %edi #base case comparison
- jle baseFib0
- movl %edi, n(%rbp)
- subl $1, %edi #subtract one, recurse
- call Fibonacci
- movl %eax, fib(%rbp)
- movl n(%rbp), %edi #restore edi value
- subl $2, %edi #subtract two, recurse
- call Fibonacci
- addl fib(%rbp), %eax
- jmp allDone
- baseFib1:
- movl $1, %eax #Fib of 1 is the base case
- jmp allDone
- baseFib0:
- movl $0, %eax #Fib of 0 is the base case
- jmp allDone
- allDone:
- movq %rbp, %rsp
- popq %rbp
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement