Phil wrote: > Hello everyone, > > With a bit more thought I was able to solve my previous question, however the > answer to this next question is beyond a simple beginner. > > I need assembly code to solve this formula: > > angle = a + (b * count) > > where > > a = 82.9 > b = -0.2 > count is a ten bit integer > angle is also an integer, so I have to add on .5 to the result > > I've been to the Microchip site where I found a lot of documents that discuss > floating point maths but no code examples. > > Can someone please help? > The best way to do this (in code space, complexity, and running time) is to use fixed point math (integers) for the entire calculation. Simply use values ten times what they need to be, and make the correction in your head. This gives: angle = 892 - 2*count Just multiply count by 10 before putting it into the calculation. The multiplication by 2 is equivalent to a bit shift to the left on count, and 16 bit integer subtraction is significantly easier than floating point subtraction. Angle will then be exactly ten times the answer you are looking for, so you then change the code that uses angle to expect a value in that range. So, instead of a bunch of floating point math, you have a multiplication, a bitshift, and a subtraction. Unless something else prevents you from doing it this way, things will be a lot easier. Daniel Imfeld -- http://www.piclist.com#nomail Going offline? Don't AutoReply us! email listserv@mitvma.mit.edu with SET PICList DIGEST in the body