elegante inversion.
/*------------------------------------------------------------------------------ INVERSION DE BYTE 8 BIT, LSB -> MSB ------------------------------------------------------------------------------*/ unsigned char mr; unsigned char invertir_byte (mr) { mr = (mr & 0x0F) << 4 | (mr & 0xF0) >> 4; mr = (mr & 0x33) << 2 | (mr & 0xCC) >> 2; mr = (mr & 0x55) << 1 | (mr & 0xAA) >> 1; return (mr); }
That is basically the solution from the post from 18-May-2010 08:57 GMT but with the difference that you save one register by being able to use the accumulator.
"...with the difference that you save one register..."
Same principle, yes.
But I'd say it not so much saving a register as saving memory, since it uses none. It only uses the standard registers and B which are freely available to be used within a function.
Look at the code produced for the compiled C if you have doubts.
Also, for what it's worth, the assembler snippet would be inherently task-safe.