Guest User

Untitled

a guest
Feb 21st, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.98 KB | None | 0 0
  1. TITLE Fibonacci Sequence (main.asm)
  2.  
  3. ; Description: Fibonacci Backwards Generator
  4. ;
  5. ; Revision date:
  6.  
  7. INCLUDE Irvine32.inc
  8. .data
  9. str1 BYTE "Enter an integer:",0
  10. intVal DWORD 1 DUP(?)
  11. fibArray DWORD 100 DUP(?)
  12.  
  13. .code
  14. main PROC
  15. call Clrscr
  16.  
  17. call PromptForInteger
  18. call Fib
  19. exit
  20. main ENDP
  21.  
  22. ;------------------------------
  23. ;PROCEDURE TO ACCEPT AN INTEGER INPUT
  24. ;---------------------------------
  25. PromptForInteger PROC
  26.  
  27. ;Display the message
  28. mov edx,offset str1
  29. call WriteString
  30.  
  31. ;Read the input from the screen
  32. call ReadInt
  33. mov intVal,eax
  34.  
  35. ;New Line
  36. call crlf
  37.  
  38. ret
  39. PromptForInteger ENDP
  40.  
  41. ;------------------------------
  42. ;PROCEDURE TO GET FIB NUMBERS
  43. ;---------------------------------
  44. Fib PROC
  45.  
  46. cmp eax,0
  47. je L1
  48. cmp eax,1
  49. je L1
  50. jmp L2
  51.  
  52. L1:
  53. mov ebx, eax
  54. jmp L3
  55. L2:
  56. dec eax
  57. push eax
  58. call Fib ;n-1
  59. pop eax
  60. mov ebx, eax
  61. dec eax
  62. push eax
  63. call Fib ;n-2
  64. pop eax
  65. add eax, ebx
  66. L3:
  67. Fib ENDP
  68.  
  69. END main
Add Comment
Please, Sign In to add comment