public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
From: Kimmo Fredriksson <kfredrik@cs.joensuu.fi>
To: gcc-help@gcc.gnu.org
Cc: y2bismil@engmail.uwaterloo.ca
Subject: Re: inline assembler
Date: Wed, 05 Nov 2003 19:07:00 -0000	[thread overview]
Message-ID: <Pine.GSO.4.58.0311052056110.16931@cs> (raw)
In-Reply-To: <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

  parent reply	other threads:[~2003-11-05 19:07 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-11-05 18:01 y2bismil
2003-11-05 18:04 ` Falk Hueffner
2003-11-05 18:13   ` y2bismil
2003-11-05 18:25     ` Falk Hueffner
2003-11-05 19:07 ` Kimmo Fredriksson [this message]
2003-11-05 19:23   ` y2bismil
  -- strict thread matches above, loose matches on Subject: below --
2000-05-18  1:17 Oldrich Kepka
2000-05-18  1:30 ` Alexandre Oliva
2000-05-19  7:57   ` Gary Funck

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.GSO.4.58.0311052056110.16931@cs \
    --to=kfredrik@cs.joensuu.fi \
    --cc=gcc-help@gcc.gnu.org \
    --cc=y2bismil@engmail.uwaterloo.ca \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).