How to read data from absolute address in delphi XE2
Asked Answered
F

1

6

Let's say that I want to read from absolute address gs:$30 in 64bit mode, so the asm code looks something like:

asm
  mov   rax, gs:[$30]
end;

...and compiler translate this code to...

  65 48 8B 05 30 00 00 00       mov rax,gs:[rel $00000030]

But I don't want to use relative address (rip + $30). I want the compiler to use absolute address and compile in this way:

  65 48 8B 04 25 30 00 00 00    mov rax,gs:[+$0030]

(It is the same, if I use gs: prefix or not!)

How do I do this?

EDIT:

I know for work-around. I ask if exist any comand to tell compiler to address location as absolute instead relative.

EDIT

So far so good... :)

drhirsch helped me to find the command, and now the compiler translates:

mov   rax, gs:[abs qword ptr $30]
or
mov   rax, gs:[abs $30]

to this:

6548A13000000000000000 mov rax,[qword $0000000000000030]

Which is almost ok :) Because I want short 32bit opcode (look upper opcodes) instlonger long 64bit opcode.

Is there any way to tell compiler to use short 32 bit address opcode instead long?

Flyer answered 15/12, 2011 at 13:51 Comment(8)
I have no 64-bit Delphi at hand, just a guess - use register instead of literal value like that: mov RAX,$30; mov RAX,gs:[RAX]Derringdo
@Serg: Sure, but this is a work-around! I ask if exist any comand to tell compiler to address location as absolute instead relative.Flyer
Why didn't you ask that in the first placeFusiform
Can't find it documented anywhere. There may be no way to force bare absolute offsets. But ask Embarcadero guys.Tichonn
@Alex: No, I have find solution, check my upper case. But I have again problems if I wont to use short 32bit opcode instead long.Flyer
Try mov rax, gs:[abs dword ptr $30] or mov rax, gs:[abs dword $30]. 676548A130000000=8 bytes.Tichonn
@Alex: No, compiler insist: [DCC Error] Project1.dpr(20): E2105 Inline assembler syntax errorFlyer
Please ask your opcode-size question separately. You've gotten an answer to the original question you asked, and it's not fair to change the question so much after you've already gotten valid answers.Kragh
F
4

You need to use the movabs instruction.

movabs  rax, gs:[$30]

Edit: rip relative addressing is the default mode, on some assemblers you may be able to force 32 bit absolute addressing with

mov rax, gs:[dword $30]  #nasm, tasm
mov rax, gs:[abs $30]    #yasm
Fusiform answered 15/12, 2011 at 14:20 Comment(6)
Hmm, but compiler insist: [DCC Error] Project1.dpr(20): E2003 Undeclared identifier: 'movabs'Flyer
And for other two methods insist: [DCC Error] Project1.dpr(21): E2105 Inline assembler syntax errorFlyer
Thanx the right way is:mov rax, gs:[abs qword ptr addr] but compiler use long 64bit opcode insted short 32bit opcode. Any idea how to solve this?Flyer
No, compiler claim: [DCC Error] Project1.dpr(20): E2107 Operand size mismatchFlyer
Why do you care which opcode the assembler chooses to use? It you want to program in opcodes, then use db to insert the opcode bytes directly into the code. Otherwise, let the assembler choose how it wishes to assemble your code. I don't see anything more to solve.Kragh
@Rob Kennedy: I'm just asking if exist regular way to set short address.Flyer

© 2022 - 2024 — McMap. All rights reserved.