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); }
"...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.