inline assembler

y2bismil@engmail.uwaterloo.ca y2bismil@engmail.uwaterloo.ca
Wed Nov 5 19:23:00 GMT 2003


[snip]
> At least gcc allows this:
> 
> #define times3(arg1) \
> ({ int x; \
>  __asm__ ( \
>    "leal (%0,%0,2),%0" \
>    : "=r" (x) \
>    : "0" (arg1)); x; })
> 
> and then you can just say:
> 
> printf("%d\n", times3(4));
> 
> I.e. compound statements return a value, if it is enclosed in parenthesis,
> and the return value has the type and value of the last statement, in this
> case the return value is the value of x, and its type is int.
> 
> Kimmo
> 

Interesting.  I didn't think of that.  Well, I think I'm just going to do things
in the simpler way.  If I need an assignment, I'll just include it as a 'dest'
parameter in the define.

If you guys don't mind...Could you check this.  
*************************************
#define KS_STORE_ESP(dest_ptr)
      __asm__ __volatile__ ( \
      "movl %%esp, (%0)" \
      : "=r" (dest_ptr)  \
      : "memory" ); 
*************************************
This simply stores the esp in a variable.  It is called like:
KS_STORE_ESP(&reg_p) ;
at the end of this reg_p should hold the value of the esp.

I MUST inlude "memory" in clobbered has *dest_ptr being modified?
Volitile is NOT needed?

Any pointers are welcome.
Thanks,

Yamin


----------------------------------------
This mail sent through www.mywaterloo.ca



More information about the Gcc-help mailing list