inline assembler
Kimmo Fredriksson
kfredrik@cs.joensuu.fi
Wed Nov 5 19:07:00 GMT 2003
On Wed, 5 Nov 2003 y2bismil@engmail.uwaterloo.ca wrote:
<snip>
> Is there a way in inline assembler to do 'real' functions? As an example
> suppose I have the following:
> #define times3(arg1)__asm__ (...); /*this results in arg1*3*/
>
> Would there be a way for me to say
> int x = times3(arg1);
Yes.
> My guess is no, but I thought I'd check anyways.
You *can*, but it is a gcc extension, not standard, I guess?
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
More information about the Gcc-help
mailing list