1.4.5. Example 2 - Packed structures

This example shows the different instructions generated for a packed structure when compiling for ARMv6 and earlier architectures.

__packed struct{
    char ch;
    short sh;
    int i;
} foo;

signed char unpack()
{
    return (signed char)foo.i;
}

Pre-ARMv6 architecture compilations

Compiling with --cpu 5 gives:

unpack PROC
       LDR      r0,|L1.24|
       PUSH     {r4,lr}
       BL       __aeabi_uread4
       LSL      r0,r0,#24
       ASR      r0,r0,#24
       POP      {r4,pc}
|L1.24|
       DCD      ||.data$0|| + 3
       ENDP

ARMv6 architecture compilations

Compiling with --cpu 6 gives:

unpack PROC
        LDR      r0,|L1.16|
        LDR      r0,[r0,#3]
        SXTB     r0,r0
        BX       lr
|L1.16|
        DCD      ||.data$0||
        ENDP
Copyright © 2002-2006 ARM Limited. All rights reserved.ARM DUI 0203G
Non-Confidential