i have got an 32bit (hexadecimal)word 0xaabbccdd and have to swap the 2. and the 3. byte. in the end it should look like 0xaaccbbdd
how can i "mask" the 2nd and the 3rd byte to first load them up to register r1 and r2 and the swap them.. i also know that i have to work with lsl and lsr commands but dont know how to start.
sorry for my bad english.hope anyone could help me out!
regards, sebastian
Back in the day we used to rely heavily on EOR for this kind of trickery.
You can do it in 4 cycles.
First off, we need the fact that: A ^ (A^B) = B
We start with 0xAABBCCDD, and we want 0xAACCBBDD. To get there, we need 0x00EEEE00^0xAABBCCDD, where EE = BB^CC.
Now, we need a few cycles to build 00EEEE00:
eor r1,r0,r0,lsr #8
and r1,r1,#0xFF00
orr r1,r1,r1,lsl #8
eor r0,r0,r1
In c:
t=x^(x>>8);
t=t&0xFF00;
t=t|(t<<8);
x^=t;
After each line, the result calculated is: starting with: AABBCCDD
eor XXXXEEXX
and 0000EE00
orr 00EEEE00
eor AACCBBDD
This will work on any 32bit ARM core.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With