Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .model small
- .stack 100h
- .data
- prev1 dw 0000h
- prev2 dw 0000h
- currNum dw 0000h
- .code
- extrn Writeint:proc, Crlf:proc
- main proc
- mov ax,@data ; copy the address of the data segment to ax
- mov ds,ax ; move the address of the data segment into the ds register
- ; initialize and print out the first number in the sequence
- mov prev1,0001h ; set the last value to 1
- mov ax,prev1 ; put the number to be displayed into ax
- mov bx,10 ; base 10
- call Writeint ; display the number
- call Crlf ; go to the next line
- mov cx,23d; ; initialize the counter to 23
- fibonacci:
- mov bx,prev1 ; move the last value into bx
- add bx,prev2 ; add the second to last value with the last value
- mov currNum,bx ; move the result into currNum
- mov bx,prev1 ; move the last value into bx
- mov prev2,bx ; set the second to last value to the last value
- mov bx,currNum ; move the current value into bx
- mov prev1,bx ; set the last value to the current value
- mov ax,currNum ; put the number to be displayed into ax
- mov bx,10 ; base 10
- call Writeint ; display the number
- call Crlf ; go to the next line
- loop fibonacci ; decrement cx and loop if cx is greater than 0
- mov ax,4C00h ; get ready to exit DOS
- int 21h ; send the command to DOS
- main endp
- end main
Add Comment
Please, Sign In to add comment