Advertisement
Lawnknome

Fibonacci loop

Jul 8th, 2015
191
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. ;calculateFib - Calculate fibonacci numbers and display
  2.    
  3.     mov ecx, fibNth                     ;sets loop counter to number nth term user requested
  4.     mov edx, 0                      ;sets edx counter to track how many terms per line
  5.  
  6. fibLoop:
  7.  
  8.     mov ebx, fib1              
  9.     mov eax, fib2
  10.     cmp edx, 5                      ;compare edx counter to 5, if equal to 5 print to new line
  11.     jne noNewLine                       ;if not equal to 5 jump to next dec print statement
  12.     call CrLf
  13.     mov edx, 0                      ;reset edx counter to 0
  14.  
  15. noNewLine:
  16.     call WriteDec
  17.     push edx                        ;push edx onto stack to allow use of edx for string
  18.     mov edx, OFFSET spaces
  19.     call WriteString
  20.     pop edx                         ;pop edx from stack and increment counter for next loop iteration
  21.     inc edx
  22.     add ebx, eax                        ;add the two terms together to get the next Fib number
  23.     mov fib2, ebx
  24.     mov fib1, eax
  25.    
  26.     loop fibLoop                        ;loop if ecx > 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement