Dennis Crawley wrote: > Andy's replay is exactly what I need. > > The only problem is when: > > a < b in the expression a + (b-a)/16 You're right, Dennis... I think that the solution is to add two lines: ; AHI:ALO = AVERAGE, NHI:NLO = NEW DATA, BHI:BLO = TEMP MOVF ALO,W ;NHI:NLO = N - A. SUBWF NLO ; MOVF AHI,W ; SKPC ; INCFSZ AHI,W ; SUBWF NHI ; SWAPF NHI,W ;BHI:W = N/16. ANDLW 00001111B ; BTFSC NHI,7 ; <--- NEW LINE ADDED IORWF 11110000B ; <--- NEW LINE ADDED MOVWF BHI ; SWAPF NLO,W ; ANDLW 00001111B ; MOVWF BLO ; SWAPF NHI,W ; ANDLW 11110000B ; IORWF BLO,W ; ADDWF ALO ;AHI:ALO = A + BHI:W. SKPNC ; INCF AHI ; MOVF BHI,W ; ADDWF AHI ; -Andy === Andrew Warren -- aiw@cypress.com === Principal Design Engineer === Cypress Semiconductor Corporation === === Opinions expressed above do not === necessarily represent those of === Cypress Semiconductor Corporation -- http://www.piclist.com hint: The list server can filter out subtopics (like ads or off topics) for you. See http://www.piclist.com/#topics