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?

PhiS
  • 4,540
  • 25
  • 35
GJ.
  • 10,810
  • 2
  • 45
  • 62
  • 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]` – kludg Dec 15 '11 at 14:16
  • @Serg: Sure, but this is a work-around! I ask if exist any comand to tell compiler to address location as absolute instead relative. – GJ. Dec 15 '11 at 14:22
  • Why didn't you ask that in the first place – Gunther Piez Dec 15 '11 at 14:28
  • Can't find it documented anywhere. There may be no way to force bare absolute offsets. But ask Embarcadero guys. – Alexey Frunze Dec 15 '11 at 14:46
  • @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. – GJ. Dec 15 '11 at 14:59
  • Try `mov rax, gs:[abs dword ptr $30]` or `mov rax, gs:[abs dword $30]`. 676548A130000000=8 bytes. – Alexey Frunze Dec 15 '11 at 15:05
  • @Alex: No, compiler insist: `[DCC Error] Project1.dpr(20): E2105 Inline assembler syntax error` – GJ. Dec 15 '11 at 15:11
  • 3
    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. – Rob Kennedy Dec 15 '11 at 16:10

1 Answers1

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
Gunther Piez
  • 29,760
  • 6
  • 71
  • 103
  • Hmm, but compiler insist: `[DCC Error] Project1.dpr(20): E2003 Undeclared identifier: 'movabs'` – GJ. Dec 15 '11 at 14:27
  • And for other two methods insist: `[DCC Error] Project1.dpr(21): E2105 Inline assembler syntax error` – GJ. Dec 15 '11 at 14:30
  • 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? – GJ. Dec 15 '11 at 14:53
  • No, compiler claim: `[DCC Error] Project1.dpr(20): E2107 Operand size mismatch` – GJ. Dec 15 '11 at 15:19
  • 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. – Rob Kennedy Dec 15 '11 at 16:09
  • @Rob Kennedy: I'm just asking if exist regular way to set short address. – GJ. Dec 15 '11 at 16:25