An inline conversion of some assembly source originally by Chan.
Converted and republished with permission under GPL.
Tested on a Mega8 @ 16Mhz running in a timer interrupt at 100kHz.
No registers were harmed in the making of this code.
Full article and code can be found here: