This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
Re: inline assembler
- From: Kimmo Fredriksson <kfredrik at cs dot joensuu dot fi>
- To: gcc-help at gcc dot gnu dot org
- Cc: y2bismil at engmail dot uwaterloo dot ca
- Date: Wed, 5 Nov 2003 21:07:21 +0200 (EET)
- Subject: Re: inline assembler
- References: <1068055268.3fa93ae4389fb@www.nexusmail.uwaterloo.ca>
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