All hail Scott, a true Wizard! This thing contains several great tricks. > movwf temp ;shift left by 2 > addwf temp,f ;by adding. puts 'a' into carry > ;and bcde into the upper nibble Very nice way to isolate the pieces needed. > andlw 7 ;grab the lower three bits > skpnc ;if the MSB ('a') was set then Depends on the carry set two instructions ago. > addlw 2 ;a*2 == 2, W = a*2 + fgh. > swapf temp,f ;put bcde into the lower nibble > subwf temp,w ;W = bcde - (a*2 +fgh) The comment doesn't say so, but of course the high nibble of W is trash right now, but .... > ;at this point, if N%9 is zero, then W contains -9,0,9 > ;so just check these three cases > > skpdc ;If W is less than 0 > addlw 9 ; then add 9 ...it doesn't matter because we use the digit carry instead of the full carry! > andlw 0x0f ;If W was/is zero then set Z ...and then (and only then!) get rid of the high order bits. > skpz ;If W is greater than 0 > addlw -9 ; then subtract 9 Very, very nice! [and I would be most surprised if anyone could improve on 12 instructions] Bob Ammerman RAm Systems (contract development of high performance, high function, low-level software) -- http://www.piclist.com hint: The PICList is archived three different ways. See http://www.piclist.com/#archives for details.