www.digitalmars.com         C & C++   DMDScript  

digitalmars.D.learn - Is there a way to load a `RIP` register relative address in inline

reply Stefanos Baziotis <sdi1600105 di.uoa.gr> writes:
I can't do for example:

lea RAX, [RIP+something];

Generally, RIP does not seem to be available.
Jun 18 2019
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Tuesday, 18 June 2019 at 16:56:18 UTC, Stefanos Baziotis wrote:
 I can't do for example:

 lea RAX, [RIP+something];

 Generally, RIP does not seem to be available.
The general trick in x86 assembly for this is call next; next: pop EAX; The call instruction pushes RIP to the stack (for a future ret instruction) but if you put it right where you are, you can simply pop it right back off the stack into another register.
Jun 18 2019
parent reply Adam D. Ruppe <destructionator gmail.com> writes:
On Tuesday, 18 June 2019 at 17:09:48 UTC, Adam D. Ruppe wrote:
 pop EAX;
errr you can see my 32 bit bias here (forgive me, I'm old), but you know what i mean :)
Jun 18 2019
parent Stefanos Baziotis <sdi1600105 di.uoa.gr> writes:
On Tuesday, 18 June 2019 at 17:10:50 UTC, Adam D. Ruppe wrote:
 On Tuesday, 18 June 2019 at 17:09:48 UTC, Adam D. Ruppe wrote:
 pop EAX;
errr you can see my 32 bit bias here (forgive me, I'm old), but you know what i mean :)
Thank you, quite clever. There is also the "$" symbol that is related: https://dlang.org/spec/iasm.html#special_symbols
Jun 18 2019