1

Following my previous question here, I have now a "error junk after expression" when the compiler try to compile the following code:

u32 jmpAdd = BW::BWFXN_SpendRepairReturnAddress;
//BW::BWFXN_SpendRepairReturnAddress has the following value: 0x0046700D
__asm__ __volatile__
(
    "movl ds:0x+57f120(, %eax, 4), %ecx\n\t"
    "jmp %0":"=m"(jmpAdd)
);

GCC gives me the following errors:

Error: junk ':0x+57f120' after expression
Error: invalid instruction suffix for 'jmp'

How can I correct those errors, please?

EDIT: the original code was the following (I converted it using ta2as v0.8.2) :

__asm
{
  mov ecx, dword ptr ds:[eax*4+0x57f120]
  jmp BW::BWFXN_SpendRepairReturnAddress
}
Community
  • 1
  • 1
kranium632
  • 45
  • 1
  • 7
  • ta2as is converting the syntax to AT&T syntax alright, but not necessarily into the proper format for inline assembly in GCC. I recommend the following two guides: http://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html and http://wiki.osdev.org/Inline_Assembly – Cody Gray - on strike Jul 31 '14 at 14:12
  • "0x+57f120" doesn't look like a valid hex literal to me, but I'm not well versed in gcc assembly. – molbdnilo Jul 31 '14 at 14:37

1 Answers1

3

Change it to the following and it should compile:

__asm__ __volatile__
(
    "movl %%ds:0x57f120(, %%eax, 4), %%ecx\n\t"
    "jmp *%0" : : "m"(jmpAdd)
);

Unfortunately, after looking at the source you're probably trying to convert it won't actually work. GCC doesn't support naked functions on x86 targets.

Ross Ridge
  • 38,414
  • 7
  • 81
  • 112