ccmny

fibonacci asm

Jul 12th, 2011
203
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .section .data
  2. .section .text
  3.  
  4. .globl _start
  5. _start:
  6.     pushl $5
  7.     call fibonacci
  8.     addl $4, %ebp
  9.     movl %eax, %ebx
  10.     movl $1, %eax
  11.     int $0x80
  12.    
  13. # Computes n-th fibonacci number
  14. # eax - result
  15. # ebx - current
  16. # ecx - last
  17. # edi - index
  18.    
  19. .type fibonacci, @function
  20. fibonacci:
  21.     pushl %ebp
  22.     movl %esp, %ebp
  23.     movl $1, %ecx
  24.     movl $1, %ebx
  25.     movl $3, %edi
  26.    
  27. loop_start:
  28.     cmpl 8(%ebp), %edi
  29.     jge end
  30.     movl %ebx, %eax
  31.     addl %ecx, %eax
  32.     movl %ebx, %ecx
  33.     movl %eax, %ebx
  34.     incl %edi
  35.     jmp loop_start
  36. end:
  37.     movl %ebp, %esp
  38.     popl %ebp
  39.     ret
Advertisement
Add Comment
Please, Sign In to add comment