News:

The new Release 25.03 is out! You can download binaries for Windows and many major Linux distros here .

Main Menu

x86 assembly problem

Started by i386, December 27, 2013, 03:56:29 PM

Previous topic - Next topic

i386

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:


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:

    .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.

ollydbg

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.

i386