Guest User

Untitled

a guest
May 22nd, 2018
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. .model small
  2. .stack 100h
  3. .data
  4. prev1 dw 0000h
  5. prev2 dw 0000h
  6. currNum dw 0000h
  7.  
  8. .code
  9.  
  10. extrn Writeint:proc, Crlf:proc
  11. main proc
  12.  
  13. mov ax,@data ; copy the address of the data segment to ax
  14. mov ds,ax ; move the address of the data segment into the ds register
  15.  
  16. ; initialize and print out the first number in the sequence
  17. mov prev1,0001h ; set the last value to 1
  18.  
  19. mov ax,prev1 ; put the number to be displayed into ax
  20. mov bx,10 ; base 10
  21. call Writeint ; display the number
  22. call Crlf ; go to the next line
  23.  
  24. mov cx,23d; ; initialize the counter to 23
  25.  
  26. fibonacci:
  27. mov bx,prev1 ; move the last value into bx
  28. add bx,prev2 ; add the second to last value with the last value
  29. mov currNum,bx ; move the result into currNum
  30.  
  31. mov bx,prev1 ; move the last value into bx
  32. mov prev2,bx ; set the second to last value to the last value
  33. mov bx,currNum ; move the current value into bx
  34. mov prev1,bx ; set the last value to the current value
  35.  
  36. mov ax,currNum ; put the number to be displayed into ax
  37. mov bx,10 ; base 10
  38. call Writeint ; display the number
  39. call Crlf ; go to the next line
  40.  
  41. loop fibonacci ; decrement cx and loop if cx is greater than 0
  42.  
  43. mov ax,4C00h ; get ready to exit DOS
  44. int 21h ; send the command to DOS
  45.  
  46. main endp
  47. end main
Add Comment
Please, Sign In to add comment