Endian swap in less than 12 instructions?
scanlime
Posts: 106
I need to swap the bytes in a long, for big-endian/little-endian conversion. So far, this is the best I can some up with- it's pretty much entirely naive and straightforward... "spi_reg" is the input and output, r0/r1 are temporaries, and "hFF00" is pre-initialized with $FF00. It's 12 instructions, or 3 instructions per swapped byte.
Have any PASM experts out there come up with a faster way of doing the same? I thought about doing something recursive with the 'rev' instruction, but the fact that it clears the non-reversed bits kind of gets in the way.
Thanks!
--Micah
mov r1, spi_reg shr r1, #24 mov r0, spi_reg shl r0, #24 or r1, r0 mov r0, spi_reg and r0, hFF00 shl r0, #8 or r1, r0 shr spi_reg, #8 and spi_reg, hFF00 or spi_reg, r1
Have any PASM experts out there come up with a faster way of doing the same? I thought about doing something recursive with the 'rev' instruction, but the fact that it clears the non-reversed bits kind of gets in the way.
Thanks!
--Micah
Comments
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
'Still some PropSTICK Kit bare PCBs left!