; fib16.asm Celio G. Nov 19, 2001 ; computes Fibonacci sequence with 16 bit precision ; save sequence in table starting at fib ; count, f0l,f0h, f1l, f1h are scratchpad variables ; last two numbers of sequence are 6FF1h and B520h list p=16F84 ; list directive to define processor #include FSR EQU 0x04 INDF EQU 0x00 w EQU 0 f EQU 1 cblock 0x10 count,f0l,f0h,f1l,f1h ;Intel memory layout endc fib EQU 0x20 ;Fibonacci numbers stored in Intel layout (low,high) ORG 0x000 main movl d'23',w mov w, count ; compute the first 23 Fibonacci numbers movl fib,w mov w,FSR clrf f0l ; 0=>f0 clrf f0h ; 0=>f0 clrf f1l clrf f1h incf f1l ; 1=> f1 loop mov f1l,w ; f1l =>w add f0l,f ; f0l+f1l =>f0l, may have Carry movf f0l,w ; get back sum into w mov w, INDF ; save in table low part of f0+f1 incf FSR ; point to next table "half entry" addcf f0h ; if Carry from previous sum, add to f0h movf f0h,w ; back into w add f1h,w ;f0h + f1h =>w mov w, INDF ; save high part of sum in memory incf FSR ; adjust pointer, xchg f1h, w ; f1h <-> w mov w,f0h ; save previous f1h in f0h xchg f1l,f0l ; low part of sum =>f1l, previous f1l>=f0l decbnz count,loop ;if count >0 go back to loop done: sleep END