gcc and registers
Posted: Thu Feb 21, 2008 8:58 pm
Hi,
I have an asm file and a C file that I compile like this:
gcc -m32 -c process.s
gcc -m32 -c mem.c
ld process.o mem.o .........
in process.s I call functions from mem.c.
At home I compile this using GCC4 and when I disassemble mem.o (the one writtin in C), I notice that only the EAX register is being used. That is fine, I rely on that because in process.s I don't want the other registers modified.
But now I compile this using GCC3.4.6 and I noticed that my function uses ECX and EDX without even pushing and poping them and at the end. So the function in process.s cannot assume that the registers it uses will still be correct after calling a function written in C.
Obviously, it is better when it uses several registers instead of memory, but it should push/pop them?
Any one have a solution for this, other than pushing my registers before calling the function? There must be a flag I could set with gcc.
I have an asm file and a C file that I compile like this:
gcc -m32 -c process.s
gcc -m32 -c mem.c
ld process.o mem.o .........
in process.s I call functions from mem.c.
At home I compile this using GCC4 and when I disassemble mem.o (the one writtin in C), I notice that only the EAX register is being used. That is fine, I rely on that because in process.s I don't want the other registers modified.
But now I compile this using GCC3.4.6 and I noticed that my function uses ECX and EDX without even pushing and poping them and at the end. So the function in process.s cannot assume that the registers it uses will still be correct after calling a function written in C.
Obviously, it is better when it uses several registers instead of memory, but it should push/pop them?
Any one have a solution for this, other than pushing my registers before calling the function? There must be a flag I could set with gcc.