For some fun I ran the equation though Proton+ the compiler I use With T1, ZCal, T2 and T2Cal as WORD vars (unsigned longs, int16)and Y as a FLOAT The code space with the equation like this y = (T1 - ((ZCal * T2) / T2Cal)) / T2Cal = 774 words Compiling to a 18f452 reduced the code to 618 words By splitting the equation into smaller sections (a very simple trick to save code) like this y = ZCal * T2 y = y / T2Cal y = (T1 - y)/ T2Cal with the 16f877 = 601 words with the 18f452 = 497 words But if you did some scaling (depends on the numbers you are working with) and changed Y to a DWORD (32 bit unsigned) the results with the same formula 16f877 = 230 words 18f452 = 229 words Tim -----Original Message----- From: pic microcontroller discussion list [mailto:PICLIST@MITVMA.MIT.EDU]On Behalf Of Martijn van Aartrijk Sent: 05 June 2003 13:11 To: PICLIST@MITVMA.MIT.EDU Subject: [PIC]: How to optimize? Hello all, I have this irritanting calculation which I must do on my PIC16F877, and I'm using CCS PIC C (PCM). Trouble is, this calculation alone takes up 4% of my code space, and I want it reduced. Unfortunately, my PIC asm isn't too good and I don't really know where to begin. I was hoping some of you might be able to help. The calculation includes a few calibration values (end on -Cal) and have to do with some timing intervals. y = (T1 - ((ZCal * T2) / T2Cal) / T2Cal; In itself, no real shocking formula. Point is, T1, ZCal, T2 and T2Cal are unsigned longs (int16), so their product is an int32. Result y is a float. As you can see, the compiler generates an incredible lot of code to handle all the int32, int16 and float stuff. So my question is: does anyone know how to handle this more efficiently? I've been trying to rewrite the equation but it doesn't seem to get any better. Thanks a lot! Martijn PS. Yes, this is a repost, but I'm still stuck with the problem. Sorry. -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu -- http://www.piclist.com hint: To leave the PICList mailto:piclist-unsubscribe-request@mitvma.mit.edu