gcc/g++ and ebp
gcc/g++ and ebp
hi,
as I have changed my message passing system (see the other thread), I now can only store three parameters (12byte) per message. This is not very much and now I want to use the last cpu register possible, namely ebp. But I don't know if this is a good idea in combination with C/C++ (gcc/g++), because normaly a copy of the original esp is stored in ebp. Ok, I know want to know, if I'm supposed to save ebp on the stack or if gcc/g++ will do that automatically when I tell it, that my inline assembly will return/need a specific value in ebp.
Now the more important question: How can I use ebp in the input/output list of the inline assembly. I mean is there something like "a", "b", "c", "d", "S", "D" for ebp? I could not find anything on the inet.
as I have changed my message passing system (see the other thread), I now can only store three parameters (12byte) per message. This is not very much and now I want to use the last cpu register possible, namely ebp. But I don't know if this is a good idea in combination with C/C++ (gcc/g++), because normaly a copy of the original esp is stored in ebp. Ok, I know want to know, if I'm supposed to save ebp on the stack or if gcc/g++ will do that automatically when I tell it, that my inline assembly will return/need a specific value in ebp.
Now the more important question: How can I use ebp in the input/output list of the inline assembly. I mean is there something like "a", "b", "c", "d", "S", "D" for ebp? I could not find anything on the inet.
Re:gcc/g++ and ebp
I don't think that gcc lets you add esp to the input/output list since it doesn't like the programmer mess with it anyway.
When you really need it, you should address it directly (by using %%esp with at&t syntax). If you need to set/get the value of esp within an inline asm statement, you should go indirectly over another register (and do a 'movl %0, %%esp', for example)
cheers Joe
When you really need it, you should address it directly (by using %%esp with at&t syntax). If you need to set/get the value of esp within an inline asm statement, you should go indirectly over another register (and do a 'movl %0, %%esp', for example)
cheers Joe
Re:gcc/g++ and ebp
You misunderstood me. I want to use ebp, not esp. Using esp would screw up everything obviouslyJoeKayzA wrote: I don't think that gcc lets you add esp to the input/output list since it doesn't like the programmer mess with it anyway.
Re:gcc/g++ and ebp
sorry, I should really think about getting glasses.....
But I think the issues are the same with ebp - it's used internally for creating frame pointers (unless you specify -fomit-frame-pointers)
But I think the issues are the same with ebp - it's used internally for creating frame pointers (unless you specify -fomit-frame-pointers)
Re:gcc/g++ and ebp
Yes, sure, but notheless my question is, if it is possible to use ebp in the inline assembly input/output register list. If so, how. Then I could test if gcc/g++ is pushing/poping ebp in order to save its value. If so, I will use it. If not I woun't.
btw. if you're using firefox, then press Strg + '+' to increase the font size and Strg + '-' to decrease it
btw. if you're using firefox, then press Strg + '+' to increase the font size and Strg + '-' to decrease it
Re:gcc/g++ and ebp
I don't recommend using EBP mixing it with c/c++ code, its better if you intend to use the register to do this entirely in assembly. If inline assembly is desirable, it should be possible only if you don't mix c/c++ code within the same function, but require that gcc allows you to create a "naked" function (one without an prologue and epilogue). A typical generated c/c++ prologue/epilogue would create/restore a stack frame looking something like this:
Now if you knock out EBP, this means you need to keep track the stack to find your parameters from current value of ESP. Also, you wouldn't be able to refer the parameter by its gcc namespace (basically plain ole assembly we got here).
Code: Select all
push ebp ; create stack frame
mov ebp, esp ; of the prologue
...
;[ebp+04h] return address
;[ebp+08h] 3rd pushed parameter
;[ebp+0Ch] 2nd pushed parameter
;[ebp+10h] 1st pushed parameter
...
mov esp, ebp ; restore stack frame
pop ebp ; of the epilogue
Re:gcc/g++ and ebp
What I meant was, (as Ryu stated above) ebp is used by the compiler internally and is not meant to be dealt with by the programmer. Therefore gcc (AFAIK) does not allow to put ebp into the input/output list. The only way is to go indirectly over another register, or even better, use a seperate pure asm routine.bluecode wrote: Yes, sure, but notheless my question is, if it is possible to use ebp in the inline assembly input/output register list. If so, how. Then I could test if gcc/g++ is pushing/poping ebp in order to save its value. If so, I will use it. If not I woun't.
Indeed, thanks!bluecode wrote: btw. if you're using firefox, then press Strg + '+' to increase the font size and Strg + '-' to decrease it
cheers Joe
Re:gcc/g++ and ebp
How do you tell people have a german keyboard...JoeKayzA wrote:Indeed, thanks!bluecode wrote: btw. if you're using firefox, then press Strg + '+' to increase the font size and Strg + '-' to decrease it
cheers Joe
You can use EBP in inline assembly. If all's ok with GCC (and I guess/expect it is) it'll either save automatically (just like with eax etc) or not at all (if you use -fomit-frame-pointer).
Code: Select all
int test(int input) {
int retval;
asm("mov %2, %1":"=a"(retval):"B"(input));
return retval;
}
Re:gcc/g++ and ebp
??? ... ok, that one took me some time, but I got it. ;DCandy wrote:How do you tell people have a german keyboard...JoeKayzA wrote:Indeed, thanks!bluecode wrote: btw. if you're using firefox, then press Strg + '+' to increase the font size and Strg + '-' to decrease it
cheers Joe
Interesting, I didn't know that either. :-[Candy wrote: You can use EBP in inline assembly. If all's ok with GCC (and I guess/expect it is) it'll either save automatically (just like with eax etc) or not at all (if you use -fomit-frame-pointer).
Should work and generate a pointless function.Code: Select all
int test(int input) { int retval; asm("mov %2, %1":"=a"(retval):"B"(input)); return retval; }
cheers Joe
Re:gcc/g++ and ebp
ROFLMAO ;DCandy wrote:How do you tell people have a german keyboard...JoeKayzA wrote:Indeed, thanks!bluecode wrote: btw. if you're using firefox, then press Strg + '+' to increase the font size and Strg + '-' to decrease it
cheers Joe
Big thanks @ all for the information
Re:gcc/g++ and ebp
I still don't get it???Quote from: Candy on 04-Jul-06, 11:39AM
Quote from: JoeKayzA on 03-Jul-06, 02:50PM
Quote from: bluecode on 03-Jul-06, 10:27AM
btw. if you're using firefox, then press Strg + '+' to increase the font size and Strg + '-' to decrease it
Indeed, thanks!
cheers Joe
How do you tell people have a german keyboard...
doesn't the inline operator thingy make the function behave like a macro and not use the stack
like this:
Code: Select all
inline unsigned int blah(unsigned int blah2){
//look! no stack
}
Re:gcc/g++ and ebp
When you call an inline function, the compiler won't allocate a new stack frame (AFAIK), but there _is_ still a stack in use, you can reference the stack pointer as well. Yes, inline functions behave a bit like macros...
But i can't see where inlining of functions was mentioned in this discussion - it was all about inline assembly statements (AFAICS).
cheers Joe
But i can't see where inlining of functions was mentioned in this discussion - it was all about inline assembly statements (AFAICS).
cheers Joe
Re:gcc/g++ and ebp
Strg is an abreviation for the german word "Steuerung", which is "control" in english. So on an english keyboard (yes, this forum is english ) it would be Ctrl.Jordan3 wrote:I still don't get it???Quote from: Candy on 04-Jul-06, 11:39AM
Quote from: JoeKayzA on 03-Jul-06, 02:50PM
Quote from: bluecode on 03-Jul-06, 10:27AM
btw. if you're using firefox, then press Strg + '+' to increase the font size and Strg + '-' to decrease it
Indeed, thanks!
cheers Joe
How do you tell people have a german keyboard...
Re:gcc/g++ and ebp
This is not working for me (gcc 3.3.6). With which version did you test it?Candy wrote:Code: Select all
int test(int input) { int retval; asm("mov %2, %1":"=a"(retval):"B"(input)); return retval; }