;*************************************************************************** ;Fibo_18 ;In a Fibonacci series each number is the sum of the two ;previous ones, e.g. 0,1,1,2,3,5,8,13,21.... ;This program calculates Fibonacci numbers within an 8-bit range, ;first going up and then down. ;Program intended for simulation only, hence no input/output. ;TJW 10.10.05 rev. 18.5.09 Tested 10.10.05 ;*************************************************************************** ;Configuration bits need not be set #include P18F2420.inc ;no i/o ports used ;These memory locations hold the Fibonnaci series. fib0 equ 10 ;lowest number (oldest when going up, newest when reversing ;down) fib1 equ 11 ;middle number fib2 equ 12 ;highest number fibtemp equ 13 ;temporary location for newest number counter equ 14 ;indicates which value we have reached, opening value is 3 org 00 ;Initialise BSR movlb 00 ;clear BSR ;preload initial values movlw 0 movwf fib0,0 movlw 1 movwf fib1,0 movwf fib2,0 movlw 3 movwf counter,0 ;have preloaded the first three numbers, so start at 3 ; forward movf fib1,0 addwf fib2,0 bc reverse ;reverse down the series if we have overflowed movwf fibtemp,0 ;latest number now placed in fibtemp incf counter,1 ;now shuffle numbers held, discarding the oldest movff fib1,fib0 movff fib2,fib1 movff fibtemp,fib2 goto forward ;when reversing down, we will subtract fib0 from fib1 to form new fib0 reverse movf fib0,0 subwf fib1,0 movwf fibtemp ;latest number now placed in fibtemp decf counter,1 ;now shuffle numbers held, discarding the oldest movff fib1,fib2 movff fib0,fib1 movff fibtemp,fib0 ;test if counter has reached 3, in which case return to forward movlw 3 cpfseq counter,0 goto reverse goto forward end