set piclist repro end I wrote this code for my project where i read a 12bit Analog value and compare it with the previous value than test if difference is not more than 0x80 steps at ones left step is from 0x00 to 0x3F right step is from from 0x80 down to 0x40 maybe some one likes to help to make better code faster because i have only 200 micro sec's pic16c84 4 MHz. i based this code on Mike Keidz sugestion with helped me a lot to get to this code thanks in advance. processor 16C84 PIC84 equ 0x00 A equ 0x0c A1 equ 0x0d B equ 0x0e B1 equ 0x0f Storlox equ 0x10 Storhix equ 0x11 Storloy equ 0x12 Storhiy equ 0x13 TmpReg1 equ 0x14 TmpReg2 equ 0x15 datalo equ 0x16 datahi equ 0x17 NULL equ 0x00 Reg0a equ 0x18 PROGRAM ORG 0x05 negate comf B,F ; two complement lowbyte incf B,F btfsc STATUS,Z decf B1,F comf B1,F ;two complement higbyte retlw NULL add movf A,W ; datalo>W addwf B,W ; add oldlobyte movwf TmpReg1 ; store difference lobyte btfsc STATUS,C ; test carry ifso incf B1,f ; incf oldhighbyte movf A1,W ; datahi>W addwf B1,W ; add oldhibyte movwf TmpReg2 ; store difference hibyte retlw NULL ; return Start movlw 0x30 ; new lowByte movwf datalo ; movlw 0x0f ; new highByte movwf datahi movlw 0xAE ; old lowByte movwf Storlox movlw 0x0E ; old highByte movwf Storhix clrf TmpReg1 ; Store diff clrf TmpReg2 ; Store diff main movf datalo,W ; new value movwf B movf datahi,W ; new value movwf B1 movf Storlox,W ; oud value movwf A movf Storhix,W ; oud value movwf A1 call negate ; nieuw negative call add ; add to old btfsc TmpReg2,0x07 ; test result goto negative ; result oldnew positive movlw 0x7F ; max value movwf A movlw 0x00 ; max value movwf A1 movf TmpReg1,W ; difference movwf B movf TmpReg2,W ; difference movwf B1 call negate ; make difference negative call add ; add btfsc TmpReg2,0x07 ; test new difference if goto negative_sub ; difference is > max value. movf TmpReg1,W ; difference movwf B movf TmpReg2,W ; difference movwf B1 call negate ; nieuw negative call add movf Storlox,W ; if positive difference movwf A ; was smaller than max movf Storhix,W ; value so old substract movwf A1 ; by new difference sould movf TmpReg1,W ; difference movwf B movf TmpReg2,W ; difference movwf B1 call negate ; nieuw negative call add ; make oldvalue = newvalue movf TmpReg1,W ; and mov it to Storlo and hi movwf Storlox movf TmpReg2,W movwf Storhix movf B,W movwf A goto Tsk2Tmp negative_sub movf Storlox,w ; old value lo movwf A movf Storhix,w ; old value hi movwf A1 movlw 0x7F ; max value lo movwf B movlw 0x00 ; max value hi movwf B1 call negate ; substract with max value call add ; so that old becomes new movf TmpReg1,W ; and mov it to Storlo and hi movwf Storlox movf TmpReg2,W movwf Storhix movf B,W movwf A goto Tsk2Tmp ; in steps not bigger than ; max value negative movlw 0x7F ; max value lo movwf A movlw 0x00 ; max value hi movwf A1 movf TmpReg1,W ; original difference movwf B movf TmpReg2,W ; still negative so movwf B1 call add ; add btfsc TmpReg2,0x07 ; test result if negative goto negativex ; goto negativex movf TmpReg1,W ; move the difference to movwf B ; B and B1 movf TmpReg2,W ; because negative change to movwf B1 ; positive and add so that call negate ; we get absolute difference call add movf Storlox,w ; old value lo movwf B movf Storhix,w ; old value hi movwf B1 movf TmpReg1,W ; move the difference to movwf A ; A and A1 movf TmpReg2,W ; movwf A1 call add ; add diffrence to old value movf TmpReg1,W ; and mov it to Storlo and hi movwf Storlox movf TmpReg2,W movwf Storhix goto Tsk2Tmp negativex movf Storlox,w ; old value lo movwf A movf Storhix,w ; old value hi movwf A1 movlw 0x7F ; max value lo movwf B movlw 0x00 ; max value hi movwf B1 call add ; so that old becomes new movf TmpReg1,W movwf Storlox movf TmpReg2,W movwf Storhix movf B,W movwf A goto Tsk2Tmp ; in steps not bigger than ; max value Tsk2Tmp movf A,W ; difference alwayas less movwf Reg0a ; than 0x80 reddy for further goto main ; processing ORG PIC84 RESETV goto Start END Marcel Elektronic Workshop Scope Amstedam.