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); }
Hi.
Only for simply "inverter routine" I have use Triscend ???
Best Regards
No, of course you don't have to - but, if you were using one, it'd be easy!
(except for the fact that Xilinx killed Triscend years ago).
just curious if anyone knows if it can be done with the uPsd (the cypress thingy)
Erik
uPSD was the ST thing (originally Waferscale) - now EoL.
"The Cypress Thing" is the PSoC - as noted above, I guess that it (or, rather, they) probably can...
;=(FUNCTION)================================================================= ; ; Name : SwapByte ; ; Action : Swap bit order within byte ; ; Parameters : UByte Src (R7) ; ; Result : UByte (R7) ; ; Notes : Src - Data byte to undergo 'swapping' ; ;=(END)====================================================================== ?PR?_SwapByte?SwapByte Segment Code Rseg ?PR?_SwapByte?SwapByte _SwapByte: MOV A,R7 ;Transfer to 'bit addressable' register MOV C,ACC.0 ;Take bits (low to high) MOV B.7,C ;Transfer to another 'bit addressible' register MOV C,ACC.1 ;And store (high to low) MOV B.6,C MOV C,ACC.2 MOV B.5,C MOV C,ACC.3 MOV B.4,C MOV C,ACC.4 MOV B.3,C MOV C,ACC.5 MOV B.2,C MOV C,ACC.6 MOV B.1,C MOV C,ACC.7 MOV B.0,C MOV R7,B ;Job done RET
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.
How about this? Only 16 bytes, and 13 clycles. both src. and des. store in acc.
mov c,acc.1 rlc a mov acc.2,c mov c,acc.3 rlc a mov acc.4,c mov c,acc.5 rlc a mov acc.6,c swap a
A neat solution. I'm going to have to remember it - Or (more likely) save to file in my 'snippet' subdirectory.
Thanks.
Just to show that there's rarely anything new when it comes to programming:
8052.com/.../90817
especially when it comes to basic programming tasks like this which has been around since the dawn of computing!