Bob, have you tried little endian notation? cblock KNOTS0 KNOTS1 endc movf KNOTS0, w clrc rrf KNOTS0, f addwf KNOTS0, f rrf KNOTS0, f clrc rrf KNOTS0, f clrc rrf KNOTS0, f addwf KNOTS0, f clrf KNOTS1 rlf KNOTS1, f Magic dozen again! :) Nikolai ---- Original Message ---- From: Bob Ammerman Sent: Wednesday, June 21, 2000 22:56:45 To: PICLIST@MITVMA.MIT.EDU Subj: [OT]: how to convert knots in Kilometers p/hour using PIC code? > But its more than 12 instructions! :-) > Bob Ammerman > RAm Systems > (high performance, high function, low-level code) > ----- Original Message ----- > From: Andrew Warren > To: > Sent: Wednesday, June 21, 2000 3:29 PM > Subject: Re: [OT]: how to convert knots in Kilometers p/hour using PIC code? >> Lea wrote: >> >> > Vel Kts / .84 = Vel Klmtrs x hour, now, How the h!@##@#@! can do this? >> >> Leandro: >> >> From Nikolai Golovchenko's code generator: >> >> ; KNOTS = KNOTS * 1.190476 >> ; >> ; ALGORITHM: >> ; Clear accumulator >> ; Add input * 1 to accumulator >> ; Add input / 8 to accumulator >> ; Add input / 16 to accumulator >> ; Move accumulator to result >> ; >> ; Error in constant approximation : 0.250001, % >> >> >> ; Input: KNOTS0 (8 bits) >> ; Output: KNOTS0 .. KNOTS1 (9 bits) >> >> cblock >> KNOTS0 >> KNOTS1 >> endc >> >> movf KNOTS0, w >> clrc >> rrf KNOTS0, f >> addwf KNOTS0, f >> rrf KNOTS0, f >> clrc >> rrf KNOTS0, f >> clrc >> rrf KNOTS0, f >> addwf KNOTS0, f >> movf KNOTS0, w >> movwf KNOTS1 >> clrf KNOTS0 >> rlf KNOTS0, f >> >> -Andy >> >> >> === Andrew Warren - fastfwd@ix.netcom.com >> === Fast Forward Engineering - San Diego, California >> === http://www.geocities.com/SiliconValley/2499