Advertisement
Guest User

Untitled

a guest
Jun 28th, 2016
222
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. Fibonacci Calculator (Input N and calculate the Nth Fibonacci Number)
  2.  
  3. 32-bit x86 machine code (hex):
  4. 8B542408 83FA0077 06B80000 0000C383
  5. FA027706 B8010000 00C353BB 01000000
  6. C9010000 008D0419 83FA0376 078BD98B
  7. B84AEBF1 5BC3
  8.  
  9. x86 assembly (MASM syntax):
  10. fib:
  11. mov edx, [esp+8]
  12. cmp edx, 0
  13. ja @f
  14. mov eax, 0
  15. ret
  16.  
  17. @@:
  18. cmp edx, 2
  19. ja @f
  20. mov eax, 1
  21. ret
  22.  
  23. @@:
  24. push ebx
  25. mov ebx, 1
  26. mov ecx, 1
  27.  
  28. @@:
  29. lea eax, [ebx+ecx]
  30. cmp edx, 3
  31. jbe @f
  32. mov ebx, ecx
  33. mov ecx, eax
  34. dec edx
  35. jmp @b
  36.  
  37. @@:
  38. pop ebx
  39. ret
  40.  
  41. C:
  42. unsigned int fib(unsigned int n)
  43. {
  44. if (n <= 0)
  45. return 0;
  46. else if (n <= 2)
  47. return 1;
  48. else {
  49. unsigned int a,b,c;
  50. a = 1;
  51. b = 1;
  52. while (1) {
  53. c = a + b;
  54. if (n <= 3) return c;
  55. a = b;
  56. b = c;
  57. n--;
  58. }
  59. }
  60. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement