David Duffy wrote: > I need to implement the following equation in a 16F876. > RESULT = (255 / A) * B > A and B are bytes (each have possible values of 01 to FF) > RESULT is a word (unsigned) for a timer routine counter. > Speed is not an issue. Code space is not really either. > .... > Actually, I can probably make the constant 256 which > means that I could put B in the high byte and then divide > by A. The error would be acceptable for the intended usage. Yeah, you could do that... Or you could leave it at 255, and do the multiplication like this: MOVF B,W MOVWF PRODUCT_HI SUBLW 0 MOVWF PRODUCT_LO DECF PRODUCT_HI That's only two instructions more than what you'd need to do a multiply by 256. > So all I really need is a 16 bit / 8 bit divide routine then? > That will give me a 16 bit result for my counter won't it? Yes. If you decide to make the constant 256, though, you can do the division in about half the time that a regular 16/8 division would take... But you already said that speed isn't an issue, so you might as well use 255 and do a full 16/8 divide. -Andy === Andrew Warren - fastfwd@ix.netcom.com === Fast Forward Engineering - San Diego, California === http://www.geocities.com/SiliconValley/2499 -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu