On Fri, 2005-07-15 at 22:26 -0700, Andrew Warren wrote: Scott Dattalo wrote: > > > I don't know what I was thinking earlier - I guess I've been > > smoking too many virtual functions here lately! > > Dude: > > Assembly = the win. C++ = the suck. > :) > P.S. Here's some better commenting (and more-descriptive register > naming): And here's a brute-force version that is a little faster, but takes more instructions: 23 instructions, 10-15 Cycles - average 13 (which is one cycle too many - there must be a way to get this to 12 cycles!) movf REGA,W subwf REGB,W ; W=B-A skpc goto L_A_GT_B ; B>=A movf REGA,W subwf REGC,W ; W=C-A skpc goto L_AisMedian ; B>=A>=C ; B>=A, C>A movf REGB,W subwf REGC,W ; W=C-B movf REGC,W ; Assume C is the median skpnc L_BisMedian: movf REGB,W ; goto done L_A_GT_B: ; A>B movf REGB,W subwf REGC,W ; W=C-B skpc goto L_BisMedian ; A>B>C ; A>B, C>=B movf REGA,W subwf REGC,W ; W=C-A movf REGC,W skpnc L_AisMedian: movf REGA,W ; C>A>B done: Scott -- http://www.piclist.com PIC/SX FAQ & list archive View/change your membership options at http://mailman.mit.edu/mailman/listinfo/piclist