Guest User

Untitled

a guest
Nov 20th, 2017
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.26 KB | None | 0 0
  1. ;Generate Fibonacci series by taking range from console
  2. .model small
  3. .data
  4. range dw ?
  5. down db ?
  6. prompt db 0ah,0dh,'enter range=$'
  7. res db 0ah,0dh,' $'
  8.  
  9. .code
  10. mov ax,@data
  11. mov ds,ax
  12. lea dx,prompt
  13. mov ah,09h
  14. int 21h
  15. mov ah,01h
  16. int 21h
  17. [mov ah,01h is a dos interrupt to take stdin input from console as char into AL reg]
  18.  
  19. and al,0fh
  20. [given range is stored into AL reg]
  21. sub al,02h
  22. [Subtract performed because fibonacci series initialized by two values 0 & 1, hence range is reduced by two]
  23.  
  24. xor cx,cx [XOR performed to clear reg values]
  25. mov cl,al
  26. mov range,cx
  27.  
  28. mov ax,0000h
  29. push ax
  30. mov bx,0001h
  31. push bx
  32. [0 & 1 starting values PUSHED into stack
  33.  
  34. mov ax,0001h; push ax; add ax,0001h; push ax
  35. these executions can also be done]
  36.  
  37. cont:add ax,bx
  38. mov dx,ax ;dx=ax+bx
  39. push dx
  40. mov ax,bx ;ax=bx
  41. mov bx,dx ;bx=dx
  42. loop cont
  43. xor bx,bx
  44. mov ax,range
  45.  
  46. add al,02h
  47. [counter size is adjusted to the actual range size by adding 2]
  48. mov down,al
  49. go1:pop bx
  50. call display
  51. dec down
  52. jnz go1
  53. mov ah,4ch
  54. int 21h
  55. .exit
  56.  
  57. display proc near
  58. mov ch,04h
  59. mov cl,04h
  60. lea dx,res ;for printing new line
  61. mov ah,09h
  62. int 21h
  63.  
  64. continue:rol bx,cl
  65. mov dl,bl
  66. and dl,0fh
  67. cmp dl,09h
  68. jg char
  69. add dl,30h
  70. jmp print
  71. char:add dl,37h
  72. print:mov ah,02h
  73. int 21h
  74. dec ch
  75. jnz continue
  76. ret
  77. display endp
  78. end
Add Comment
Please, Sign In to add comment