This is the mail archive of the binutils@sources.redhat.com mailing list for the binutils project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: Is this correct ?


Hi Tat Kee Tan,

> I have this C code which is compiled using arm-linux-gcc 2.95.3

First of all, this question should have been posted to the gcc-help
mailing list (gcc-help@gcc.gnu.org), not the binutils list, since it
is about code geenration by the compiler.

> Using one ldr instruction should get to the value of prev_limit,
> why does it take a sequence of two ldr instructions ? See below

>     80d4:       e59f3044        ldr     r3, [pc, #44]   ; 8120
>     80dc:       e5933000        ldr     r3, [r3]

The reason is that 'prev_limit' is a static variable, not a local
variable.  Therefore it will be stored in the .data section and not on
the stack.  Since the compiler does not know where the .data section
will be located in memory it cannot just use a pc-relative load to get
the value.  Instead the address of 'prev_limit' has to be stored in a
word at the end of the get_request() function, and then two LDRs are
used to load the value.  The first LDR loads the address of
'prev_limit' from the word at the end of the function.  The second LDR
loads the contents of this address into R3.

Cheers
        Nick


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]