* loading data addresses on Alpha
@ 1996-05-02 4:00 Craig Partridge
1996-05-03 4:00 ` Roger Ivie
1996-05-07 4:00 ` Greg Lueck Development Environment
0 siblings, 2 replies; 3+ messages in thread
From: Craig Partridge @ 1996-05-02 4:00 UTC (permalink / raw)
Hi:
I've got a quick (and possibly stupid) question.
How does one load addresses into registers on the Alpha?
Having plowed through the manuals and various bits of code, it appears there
are two choices:
* I can laboriously load 16-bits of the address at a time using
LDA and LDAH and one shift. This eats several instructions.
* Various assemblers seem to offer a single instruction macro expansion of
LDA, that loads a particular address using some offset from (I believe)
the global pointer (GP). What I can't puzzle out is how this is done
and how GP is initialized.
I'm trying to puzzle this out since I'm doing some assembly hacking in an
environment which does not use the standard register assignments.
Anyone got some tips?
Thanks!
Craig
craig@bbn.com
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: loading data addresses on Alpha
1996-05-02 4:00 loading data addresses on Alpha Craig Partridge
@ 1996-05-03 4:00 ` Roger Ivie
1996-05-07 4:00 ` Greg Lueck Development Environment
1 sibling, 0 replies; 3+ messages in thread
From: Roger Ivie @ 1996-05-03 4:00 UTC (permalink / raw)
In article <Dqs8D7.7A3@world.std.com>, craigp@world.std.com (Craig Partridge) writes:
Well, after my fiasco discussing MSCP and bad block replacement on port-vax,
I promised myself I wouldn't post about things I didn't know really well. I just
couldn't resist this one, though...
> How does one load addresses into registers on the Alpha?
>
> Having plowed through the manuals and various bits of code, it appears there
> are two choices:
>
> * I can laboriously load 16-bits of the address at a time using
> LDA and LDAH and one shift. This eats several instructions.
>
> * Various assemblers seem to offer a single instruction macro expansion of
> LDA, that loads a particular address using some offset from (I believe)
> the global pointer (GP). What I can't puzzle out is how this is done
> and how GP is initialized.
Your choices are basically load it using LDA and LDAH etc. or arrange to have
a location lying around somewhere convenient containing the valud you need
to load.
The address of a procedure on the Alpha is really the address of a record
containing a pair of addresses: the entry point of the procedure and the
value that should be loaded into one of the other registers so that
procedure can get to its constants (the "literal pool"). It's been a while
since I dorked with this stuff, but you should be able to see this happen
in MACRO32 if you compile with /list/show=machine. In the expansion of the
single-word LDA equivalent, you should see a reference through the pointer
into the literal pool to a word containing the value; i.e., the LDA expands
into an instruction and a data word.
--
-------------------------+---------------------------------------------
Roger Ivie | P v Q -> P
ivie@cc.usu.edu | -- Gordon B. Hinckley
http://cc.usu.edu/~ivie/ |
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: loading data addresses on Alpha
1996-05-02 4:00 loading data addresses on Alpha Craig Partridge
1996-05-03 4:00 ` Roger Ivie
@ 1996-05-07 4:00 ` Greg Lueck Development Environment
1 sibling, 0 replies; 3+ messages in thread
From: Greg Lueck Development Environment @ 1996-05-07 4:00 UTC (permalink / raw)
The compiler load addresses from a table of address literals. The $gp
register is reserved to point at this table, so a typical address load
looks like this:
ldq $rx, disp($gp)
where "disp" is the appropriate displacement to reference the desired
element in the table. The compilers also generate code to set up the
$gp register upon entry to a procedure. You'll notice at the start of
each procedure there is code like this:
ldah $gp, disp1($pv)
lda $gp, disp2($gp)
This sets the $gp register by adding a 32-bit constant to the $pv
register. The calling standard on Digital Unix Alpha dictates that $pv
be set to the address of the called procedure. Therefore, there is a
limitation that the address literal table be within a 32-bit offset from
every procedure that uses it.
Since it sounds like you are in your own environment, you can either
choose to use this mechanism or choose another that is more appropriate
to your needs. For instance, if address loads are uncommon, you can
avoid reserving a register and generate code like this to load an
address:
br $rx, 0 ; Branch to next instruction, $rx set to
; address following branch
ldah $rx, disp1($rx)
ldq $rx, disp2($rx)
This loads an address from a table that is indexed by adding a 32-bit
displacement to the current PC. Note, the whole sequence uses only one
register.
Another option is to load addresses like this:
br $rx, L1 ; $rx set to address following branch
<low 32 bits of address>
<high 32 bits of address>
L1: ldq $rx, 0($rx)
However, this is rather messy because it mixes text and data together.
Also, you need to get the alignment of the branch instruction right or
the address load will be unaligned.
Hope this helps.
--
-------------------------------------------------------------------------------
Greg Lueck Currently contracting at Digital
Doan & Associates, Ltd. lueck@zk3.dec.com
Opinions expressed herein are my own.
-------------------------------------------------------------------------------
--
-------------------------------------------------------------------------------
Greg Lueck Currently contracting at Digital
Doan & Associates, Ltd. lueck@zk3.dec.com
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1996-05-07 4:00 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
1996-05-02 4:00 loading data addresses on Alpha Craig Partridge
1996-05-03 4:00 ` Roger Ivie
1996-05-07 4:00 ` Greg Lueck Development Environment
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox