Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: i386 on December 27, 2013, 03:56:29 pm

Title: x86 assembly problem
Post by: i386 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

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
    .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.
Title: Re: x86 assembly problem
Post by: ollydbg 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.
Title: Re: x86 assembly problem
Post by: i386 on December 28, 2013, 04:23:45 am
Thanks. It's solved.