ARM Assembly - Converting Endianness

Posted by SoulBeaver on Stack Overflow See other posts from Stack Overflow or by SoulBeaver
Published on 2010-05-02T21:58:11Z Indexed on 2010/05/02 22:08 UTC
Read the original article Hit count: 281

Filed under:
|
|

Hello people!

This is currently a homework project that me and my teammate are stuck on. We haven't been given much of an introduction into Assembly, and this is supposed to be our first homework exercise. The task is to create a program that converts 0xAABBCCDD into 0xDDCCBBAA.

I'm not looking for an answer, as that would defeat the purpose, but we are getting severely frustrated over the difficulty of this stupid thing. We think we have a good start in creating a viable solution, but we just cannot come up with the rest of the program.

First, we mask every single tupel (aa), (bb), (cc), (dd) into a different register:

LDR R0, LittleEndian    // 0xAABBCCDD
AND R1, R0, #0xFF000000 // 0xAA
AND R2, R0, #0x00FF0000 // 0xBB
AND R3, R0, #0x0000FF00 // 0xCC
AND R4, R0, #0x000000FF // 0xDD

Then we try to re-align them into the R0 register, but hell if we could come up with a good solution...

Our best effort came from:

ORR R0, R1, LSL #24 
ORR R0, R2, LSL #8
ORR R0, R3, LSR #8
ORR R0, R4, LSR #24

which produced 0xBBBBCCDD for some odd reason; we really don't know.

Any hints would be greatly appreciated. Again, we are asking for help, but not for a solution.

Cheers!

© Stack Overflow or respective owner

Related posts about arm

Related posts about assembly