0

Using ARM assembly, I want to load R0 with predefined bytes A, B, C, D. In the .data section I have them defined as:

A:    .byte    0xFF
B:    .byte    0xAA
C:    .byte    0x88
D:    .byte    0x77

I want R0 to be FFAA8877 when all is said and done. Not sure I should be using .byte or .word or even something else for A, B, C, D.

EDIT: Here is what I'm trying to do with R0:

@on entry: R0 holds the word to be swapped
@on exit: R0 holds the swapped word, R1 is destroyed
@R0 = A, B, C, D
byteswap:
    EOR R1, R0, R0, ROR #16
    BIC R1, R1, #0xFF0000
    MOV R0, R0, ROR #8
    EOR R0, R0, R1, LSR #8
2
  • 1
    If you really need to have them in the datasection for some reason, just define it as MyValue: .word 0xFFAA8877 and later in the code use ldr r0, =MyValue and ldr r0, [r0] The first will load the address the second will load from that address. Commented Oct 6, 2013 at 21:58
  • The reason why I need A, B, C, D is to byteswap R0 Commented Oct 6, 2013 at 22:36

2 Answers 2

1

Here is a shortcut.

ldr r0,=0xFFAA8877 

Or you can do the same thing manually...

ldr r0,my_number
...
my_number: .word 0xFFAA8877
Sign up to request clarification or add additional context in comments.

Comments

0

Assuming you are running little-endian ARM, here is how you can do it:

ldr r0, =A
ldr r1, [r0]
rev r0, r1

Note that the rev instruction does the conversion from little-endian to big-endian. Note that the rev instruction is available only armv6+.

If you are running big-endan ARM, just skip the rev instruction and you'll be fine :)

Edit: rev instruction was incorrect.

1 Comment

The purpose of this is to swap the bytes of R0 between little-endian and big-endian. I'll add the instructions to the OP

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.