Author Topic: x86 assembly problem  (Read 3245 times)

Offline i386

  • Single posting newcomer
  • *
  • Posts: 3
x86 assembly problem
« on: December 27, 2013, 03:56:29 pm »
I am using windows version code blocks 12.11, with integrated 32bit mingw gcc 4.7.1 on Windows 8.1.

In the file main.c, the related code is:
Code: [Select]

int func(void);

int main(void)
{
    unsigned int reg = 0;

    __asm volatile
    (
        "mov ebx, esp\n\t"
        "mov eax, fs : [ebx]\n\t"
        "mov %0, eax"
        : "=m"(reg)
    );

    reg = func();

    return 0;
}

In the file func.S, the related code is:
Code: [Select]
    .text
    .global _func
_func:
    enter 0, 0

    mov ebx, esp
    mov eax, fs : [ebx] ##### This is line 26

    leave
    ret

The full compile log is:
-------------- Build: Debug in win (compiler: GNU GCC Compiler)---------------

mingw32-gcc.exe -Wall  -g  -m80387 -std=c99 -masm=intel -Wa,-msyntax=intel,-mnaked-reg    -c D:\CB\win\main.c -o obj\Debug\main.o
mingw32-g++.exe -Wall  -g  -m80387 -std=c99 -masm=intel -Wa,-msyntax=intel,-mnaked-reg    -c D:\CB\win\func.S -o obj\Debug\func.o
D:\CB\win\func.S: Assembler messages:
D:\CB\win\func.S:26: Error: junk `:[ebx]' after expression

As I used some x87 FPU instructions and 'long double' data type, so I add '-m80387 -std=c99' option.
I like 'intel assembly format', so I add '-masm=intel -Wa,-msyntax=intel,-mnaked-reg' option.

The instruction "mov eax, fs : [ebx]" is in both files, but the main.c compile ok and the other fail.
« Last Edit: December 27, 2013, 04:00:07 pm by i386 »

Online ollydbg

  • Developer
  • Lives here!
  • *****
  • Posts: 5223
  • OpenCV and Robotics
    • Chinese OpenCV forum moderator
Re: x86 assembly problem
« Reply #1 on: December 27, 2013, 04:09:37 pm »
Welcome, but I think it is not an issue related to C::B?
You should asked this kind of question in stackoverflow or some other maillist.
If some piece of memory should be reused, turn them to variables (or const variables).
If some piece of operations should be reused, turn them to functions.
If they happened together, then turn them to classes.

Offline i386

  • Single posting newcomer
  • *
  • Posts: 3
Re: x86 assembly problem
« Reply #2 on: December 28, 2013, 04:23:45 am »
Thanks. It's solved.