Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- INCLUDE Irvine32.inc
- .data
- fibHeader BYTE "The first 10 numbers in the fibonacci series are:", 0
- fibArray DWORD 10 DUP(0)
- .code
- main PROC
- mov edx, OFFSET fibHeader ; print out fibonacci heading using edx due to WriteString call
- Call WriteString ; prints the fibHeader
- Call Crlf ; new line
- ; initialize registers
- mov eax, 0 ;first fib value
- mov fibArray+4, eax
- call WriteDec ;print first fib value (0)
- call crlf
- mov eax, 1
- mov ebx, 0 ; move first fib value to ebx
- call WriteDec
- call crlf
- mov edx, 1 ; move second fib value to edx
- mov fibArray+4, edx ; store the second Fib value
- ; prepare to loop
- mov ecx, 8 ; loop counter for 8 more values
- mov esi, OFFSET fibArray+4 ; array index for 3rd Fib value
- ; loop iteration
- ; array storage
- L1:
- mov eax, ebx ; eax = ebx
- add [esi], eax ; store the Fib value in the array
- add eax, edx ; eax = eax + edx
- Call WriteDec ; print the next number in the series
- Call Crlf ; new line
- mov ebx, edx ; prepare for next iteration
- mov edx, eax
- add esi, type fibArray ; increment the array index
- LOOP L1 ; if ECX > 0, ECX--, go to L1
- add [esi], eax ; store the last Fib value in the array
- mov ecx, 9
- mov esi, OFFSET fibArray+4
- L2:
- mov eax, [esi]
- call WriteDec
- call Crlf
- add esi, type fibArray
- LOOP L2
- call dumpregs
- exit
- main ENDP
- end main
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement