Although one liners are nice, they're not necessarily faster. Multiplication instructions are always SLOW. Once you get to the point where the lines of code are that horribly long (and having non-bitwise operators), I'd question the speed/code size improvements, if any.
In response to the comment about eliminating 'if' statements for speed: you're right and wrong. With today's modern processors you generally want to avoid using 'if' statements as much as possible due to branch prediction. However, I don't believe the simple processor on the BASIC STAMP implements pipelining. You'd probably be taking more cycles, and probably more memory as well, by doing all of that math than if you simply used 'if' statements.
My favorite line from my optimized code is:
Dr_Motor3 = (40 << (~(basket_lift | basket_lower)) << 2) | (15 >> (~(basket_lift) << 2))
It effectively eliminated a 4 condition branch statement ;-)
PBASIC was so horrible that I *wanted* to program in assembly.
__________________
MTV is my source for new and original music
|