I did a divide by 255 once for 24 bits that went something like this: /* good for up to 255*0xFFFF, that is 0x1000000 (16megs) - 0x100ff */ result = ((dividend+1 + ((dividend+1)/256) ) / 256); *remainder = (dividend - (result*256)) + result; *remainder = result + dividend - (result*256)) This is pseudo code that should actually work but I have optimized it for the CCS from here. IIRC, the main reason I did not use the above verbatim is to be able to support 24 bits. Keep an eye on the .LST file. Of course the div and mult 256 is easy with shifts. It was good (tested on a pc platform with Borland C) to 16 Megs and saved a ton of code. Since it works by aproximation, sometimes the remainder needs adjustment. That is the last two statements. David Koski david@KosmosIsland.com On Fri, 1 Feb 2002 20:50:46 -0200 Edson Brusque wrote: > Hello, > > I need to multiply a byte by another byte and then divide this result by > 255, like x = y * z / 255. > > At this moment, I'm using CCS-PICC built-in maths, but it's very > inneficient. The execution time for this calculation is about 1200 > instructions(!). > > Someone have an idea of a very fast math function in assembly to make > this? > > Best regards, > > Brusque > > ----------------------------------- > Edson Brusque > Research and Development > C.I.Tronics Lighting Designers Ltda > Blumenau - SC - Brazil > www.citronics.com.br > Say NO to HTML mail > ----------------------------------- > > -- > http://www.piclist.com hint: PICList Posts must start with ONE topic: > [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads > -- http://www.piclist.com hint: PICList Posts must start with ONE topic: [PIC]:,[SX]:,[AVR]: ->uP ONLY! [EE]:,[OT]: ->Other [BUY]:,[AD]: ->Ads