Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;Generate Fibonacci series by taking range from console
- .model small
- .data
- range dw ?
- down db ?
- prompt db 0ah,0dh,'enter range=$'
- res db 0ah,0dh,' $'
- .code
- mov ax,@data
- mov ds,ax
- lea dx,prompt
- mov ah,09h
- int 21h
- mov ah,01h
- int 21h
- [mov ah,01h is a dos interrupt to take stdin input from console as char into AL reg]
- and al,0fh
- [given range is stored into AL reg]
- sub al,02h
- [Subtract performed because fibonacci series initialized by two values 0 & 1, hence range is reduced by two]
- xor cx,cx [XOR performed to clear reg values]
- mov cl,al
- mov range,cx
- mov ax,0000h
- push ax
- mov bx,0001h
- push bx
- [0 & 1 starting values PUSHED into stack
- mov ax,0001h; push ax; add ax,0001h; push ax
- these executions can also be done]
- cont:add ax,bx
- mov dx,ax ;dx=ax+bx
- push dx
- mov ax,bx ;ax=bx
- mov bx,dx ;bx=dx
- loop cont
- xor bx,bx
- mov ax,range
- add al,02h
- [counter size is adjusted to the actual range size by adding 2]
- mov down,al
- go1:pop bx
- call display
- dec down
- jnz go1
- mov ah,4ch
- int 21h
- .exit
- display proc near
- mov ch,04h
- mov cl,04h
- lea dx,res ;for printing new line
- mov ah,09h
- int 21h
- continue:rol bx,cl
- mov dl,bl
- and dl,0fh
- cmp dl,09h
- jg char
- add dl,30h
- jmp print
- char:add dl,37h
- print:mov ah,02h
- int 21h
- dec ch
- jnz continue
- ret
- display endp
- end
Add Comment
Please, Sign In to add comment