Advertisement
Guest User

Untitled

a guest
Oct 19th, 2017
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1.  
  2.  
  3. INCLUDE Irvine32.inc
  4.  
  5. .data
  6. fibHeader BYTE "The first 10 numbers in the fibonacci series are:", 0
  7. fibArray DWORD 10 DUP(0)
  8.  
  9. .code
  10. main PROC
  11.  
  12. mov edx, OFFSET fibHeader ; print out fibonacci heading using edx due to WriteString call
  13. Call WriteString ; prints the fibHeader
  14. Call Crlf ; new line
  15.  
  16. ; initialize registers
  17. mov eax, 0 ;first fib value
  18. mov fibArray+4, eax
  19. call WriteDec ;print first fib value (0)
  20. call crlf
  21. mov eax, 1
  22. mov ebx, 0 ; move first fib value to ebx
  23. call WriteDec
  24. call crlf
  25. mov edx, 1 ; move second fib value to edx
  26. mov fibArray+4, edx ; store the second Fib value
  27.  
  28.  
  29. ; prepare to loop
  30. mov ecx, 8 ; loop counter for 8 more values
  31. mov esi, OFFSET fibArray+4 ; array index for 3rd Fib value
  32.  
  33. ; loop iteration
  34. ; array storage
  35.  
  36. L1:
  37. mov eax, ebx ; eax = ebx
  38. add [esi], eax ; store the Fib value in the array
  39. add eax, edx ; eax = eax + edx
  40.  
  41. Call WriteDec ; print the next number in the series
  42. Call Crlf ; new line
  43. mov ebx, edx ; prepare for next iteration
  44. mov edx, eax
  45. add esi, type fibArray ; increment the array index
  46. LOOP L1 ; if ECX > 0, ECX--, go to L1
  47.  
  48. add [esi], eax ; store the last Fib value in the array
  49.  
  50.  
  51.  
  52. mov ecx, 9
  53. mov esi, OFFSET fibArray+4
  54.  
  55. L2:
  56.  
  57. mov eax, [esi]
  58. call WriteDec
  59. call Crlf
  60. add esi, type fibArray
  61. LOOP L2
  62.  
  63. call dumpregs
  64.  
  65. exit
  66. main ENDP
  67. end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement