flat assembler
Message board for the users of flat assembler.

Index > Main > RIP-relative data-addressing, in long mode,

Author
Thread Post new topic Reply to topic
lazer1



Joined: 24 Jan 2006
Posts: 185
lazer1 16 Apr 2006, 15:54
for 64 bit long mode,

AMD vol2, 1.3.2 on page 15 says:

Quote:

New RIP-relative data-addressing mode.


can someone give an example of how this is
used?

Razz
Post 16 Apr 2006, 15:54
View user's profile Send private message Reply with quote
Chewy509



Joined: 19 Jun 2003
Posts: 297
Location: Bris-vegas, Australia
Chewy509 17 Apr 2006, 23:24
In Long mode, all immediates (when used for addresses) are sign extended 32bit values.

However this leads to a problem, where if you want an absolute memory address (since your limited to 32bit signed immediate), you're limited to 2GB from 0 -> 2GB. Not good. So AMD decided to have the offset be taken from RIP instead of 0, which allows you to access +-2GB using an immediate offset from the current code location.

The advantage in this is, most data is normally located with +-2GB of the code executing, (not within 0->2GB of memory), so it gives easy access to your data without requiring the use of a another register. The other added benefit, is that it make produced PIC (position independent code) easier as well, as long as your data is tightly coupled with your code.
Post 17 Apr 2006, 23:24
View user's profile Send private message Visit poster's website Reply with quote
lazer1



Joined: 24 Jan 2006
Posts: 185
lazer1 19 Apr 2006, 02:57
Chewy509 wrote:
In Long mode, all immediates (when used for addresses) are sign extended 32bit values.


do you mean that with the following code it isnt using
a 64 bit value for [xyz] Question

Code:
   org 123456789ah

use 16

   ; ..... set up 64 bit ....

use64
   ....
   mov [xyz],rbx

xyz:     dq  1


    


Quote:

The advantage in this is, most data is normally located with +-2GB of the code executing,


not if you were editting an uncompressed film in VM,

are you sure about this?

Thomas where are you? Razz

Just when I was starting to think that long mode was good,

I think you can hack around this problem like so:
Code:

    mov rax,23456789abh
    mov [rax],rbx

    


that will give you an absolute address above 32 bits,
Post 19 Apr 2006, 02:57
View user's profile Send private message Reply with quote
lazer1



Joined: 24 Jan 2006
Posts: 185
lazer1 19 Apr 2006, 04:56
Chewy509 wrote:
In Long mode, all immediates (when used for addresses) are sign extended 32bit values.


ok, I've verified what you've said via fasm, Surprised

I assembled the following file:

Code:
        org 1234567887654321

use64
        mov [xyz],rbx

xyz:    db 0
    


and got the following fasm output:

Code:
G:\fasm>
G:\fasm>fasm test64\address64.asm
flat assembler  version 1.64
2 passes, 8 bytes.

G:\fasm>
    


and the hex looks like this:

Code:
0000: 48891D00 00000000                      H.......
    


so it is clearly not using absolute 64 bit addressing, Crying or Very sad

Note that although the x86 MMU implements a lot less than 64 bits
that the above is syntactically correct though it wont run as its
too big an address,

thats a CPU problem not a fasm problem! Rolling Eyes
Post 19 Apr 2006, 04:56
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2023, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.