This is the mail archive of the
binutils@sources.redhat.com
mailing list for the binutils project.
Re: Is this correct ?
- To: Nick Clifton <nickc at cambridge dot redhat dot com>
- Subject: Re: Is this correct ?
- From: Richard Earnshaw <rearnsha at arm dot com>
- Date: Tue, 12 Jun 2001 13:05:18 +0100
- cc: Tat Kee Tan <tktan at EE dot Princeton dot EDU>, binutils at sources dot redhat dot com, Richard dot Earnshaw at arm dot com
- Organization: ARM Ltd.
- Reply-To: Richard dot Earnshaw at arm dot com
> > 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.
Nearly, but not quite.
On the ARM, the pc-relative load is limited to a range of +/- 4Kbytes from
the current address. Since we cannot guarantee that the local variable
will be in that range (in fact we can virtually guarantee that it won't --
most of that range will be code not data) we must use a pc-relative load
to get the address of the variable and then load its value using that.
> 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.
R.