This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

How the assembler command 'ldrb' works

Note: This was originally posted on 9th September 2011 at http://forums.arm.com

Hi,

arch/arm/boot/compressed/head.S (Linux Kernel 3.0.x source)

                /*
              * The kernel build system appends the size of the
              * decompressed kernel at the end of the compressed data
              * in little-endian form.
              */
                ldrb    r9, [r10, #0]
                ldrb    lr, [r10, #1]
                orr  r9, r9, lr, lsl #8
                ldrb    lr, [r10, #2]
                ldrb    r10, [r10, #3]
                orr  r9, r9, lr, lsl #16
                orr  r9, r9, r10, lsl #24

Because the size of decompressed kernel is appended at the end of the compressed data in little-endian form,
the above codes change its byte order to load it into a register.

If a value in the memory is 0x12345678,
it's stored like [78|56|34|12] in the ARM architecture memory space. (in little-endian mode)
And, after the above codes are excuted, it's loaded like [12345678] in the r9 register.

But why is the command 'ldrb' used in the above codes?
Even if just the command 'ldr' is used, the result is same.
And besides, it's far much more simple.


ldr r9 [r10]

The above code also changes its byte order.
It's also loaded like [12345678] in the r9 register.

In big-endian mode of ARM, the result is different??
0