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!
On ARMv6 and above, you can just use the rev instruction, but I assume that you're not allowed to do that for whatever reason.
As to why you got the result you did, I've gone through your code and commented the actual values of the registers being operated upon:
LDR R0, LittleEndian // r0 = 0xAABBCCDD
AND R1, R0, #0xFF000000 // r1 = 0xAA000000
AND R2, R0, #0x00FF0000 // r2 = 0x00BB0000
AND R3, R0, #0x0000FF00 // r3 = 0x0000CC00
AND R4, R0, #0x000000FF // r4 = 0x000000DD
ORR R0, R1, LSL #24 // r0 = 0xAABBCCDD | 0x00000000 = 0xAABBCCDD
ORR R0, R2, LSL #8 // r0 = 0xAABBCCDD | 0xBB000000 = 0xBBBBCCDD
ORR R0, R3, LSR #8 // r0 = 0xBBBBCCDD | 0x000000CC = 0xBBBBCCDD
ORR R0, R4, LSR #24 // r0 = 0xBBBBCCDD | 0x00000000 = 0xBBBBCCDD
What's happening here is that you have your shift directions backwards; instead of left shifting 0xAA000000 by 24, you want to right shift it by 24, giving 0x000000AA. Furthermore, you never zeroed out the contents of r0, which you would also need to do for this approach to work. If you fix these problems, your code will work as intended (though there are more compact ways to accomplish the same task).
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