; fib0.asm Computes the Fibonacci sequence with 8 bits precision ; Celio Guimaraes 20 Nov 2001 ; uses macro xchg to exchange contents of two file regs, ; or a file register and W using three xor insructions (adapted from I. M. Cenov); ; macros mov, movl and add are "syntactic sugar" for the unatural ; original Microchip mnemonics. list p=16F84 errorlevel 1, -305 ; suppress warning message for taking f as default operand #include ; macros mov, movl, add, xchg (and others) INDF equ 0 FSR equ 4 cblock 0xc f0,f1 ; f0 and f1 are scratchpad variables endc cblock 0x10 fib0,fib1,fib2 ; ram vector to store computed Fib numbers endc ORG 0x000 clrf fib0 ; 0=>fib0 clrf fib1 incf fib1 ; 1=> fib1 movl fib2,w ; address of fib2 => w mov w, FSR ; w => FSR clrf f0 ; 0=>f0 clrf f1 incf f1 ; 1=> f1 loop mov f0,w ; f0 =>w add f1,w ; f0+f1 =>w bc done ; if CY, result oveflows 8 bits, so finish mov w,INDF ; store new Fib number in ram xchg f1,w ; f1=> w, f0+f1 =>f1 mov w,f0 ; f0 gets previous value of f1 incf FSR b loop done: sleep END