public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* inline assembler
@ 2000-05-18  1:17 Oldrich Kepka
  2000-05-18  1:30 ` Alexandre Oliva
  0 siblings, 1 reply; 9+ messages in thread
From: Oldrich Kepka @ 2000-05-18  1:17 UTC (permalink / raw)
  To: gcc-help

Hi.

Do anybody know about some good document about inline assembler in gcc.

Thanks


Oldřich Kepka
skola@sanitas.cz
http://www.sanitas.cz/~kepka

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: inline assembler
  2000-05-18  1:17 inline assembler Oldrich Kepka
@ 2000-05-18  1:30 ` Alexandre Oliva
  2000-05-19  7:57   ` Gary Funck
  0 siblings, 1 reply; 9+ messages in thread
From: Alexandre Oliva @ 2000-05-18  1:30 UTC (permalink / raw)
  To: Oldrich Kepka; +Cc: gcc-help

[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 464 bytes --]

On May 18, 2000, "Oldrich Kepka" <gcc@sanitas.cz> wrote:

> Do anybody know about some good document about inline assembler in gcc.

How about the GCC manual, for a start?

-- 
Alexandre Oliva    Enjoy Guaraná, see http://www.ic.unicamp.br/~oliva/
Cygnus Solutions, a Red Hat company        aoliva@{redhat, cygnus}.com
Free Software Developer and Evangelist    CS PhD student at IC-Unicamp
oliva@{lsd.ic.unicamp.br, gnu.org}   Write to mailing lists, not to me

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: inline assembler
  2000-05-18  1:30 ` Alexandre Oliva
@ 2000-05-19  7:57   ` Gary Funck
  0 siblings, 0 replies; 9+ messages in thread
From: Gary Funck @ 2000-05-19  7:57 UTC (permalink / raw)
  To: Alexandre Oliva, Oldrich Kepka; +Cc: gcc-help

On May 18,  5:30am, Alexandre Oliva wrote:
> Subject: Re: inline assembler
> 
On May 18, 2000, "Oldrich Kepka" <gcc@sanitas.cz> wrote:
> 
> > Do anybody know about some good document about inline assembler in gcc.
> 
> How about the GCC manual, for a start?

On Linux, or any system where "info" is installed.  Try "info gcc", to
access the GCC manual, then select "C extensions", and "Extended Asm."
for details.

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: inline assembler
  2003-11-05 19:07 ` Kimmo Fredriksson
@ 2003-11-05 19:23   ` y2bismil
  0 siblings, 0 replies; 9+ messages in thread
From: y2bismil @ 2003-11-05 19:23 UTC (permalink / raw)
  To: gcc-help

[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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: inline assembler
  2003-11-05 18:01 y2bismil
  2003-11-05 18:04 ` Falk Hueffner
@ 2003-11-05 19:07 ` Kimmo Fredriksson
  2003-11-05 19:23   ` y2bismil
  1 sibling, 1 reply; 9+ messages in thread
From: Kimmo Fredriksson @ 2003-11-05 19:07 UTC (permalink / raw)
  To: gcc-help; +Cc: y2bismil

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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: inline assembler
  2003-11-05 18:13   ` y2bismil
@ 2003-11-05 18:25     ` Falk Hueffner
  0 siblings, 0 replies; 9+ messages in thread
From: Falk Hueffner @ 2003-11-05 18:25 UTC (permalink / raw)
  To: y2bismil; +Cc: GCC- help

y2bismil@engmail.uwaterloo.ca writes:

> > static inline int times3(int x) {
> >   int r;
> >   asm(...);
> >   return r; 
> > }
> 
> Yeah, I was thinking about that.  But I'm a bit hesitent to do that.
> I'm not quite sure how it would affect the program.  Some parts
> don't want the stack modified...so this might cause a problem with
> function calls.

You can force inlining with __attribute__((always_inline)) or
something.

-- 
	Falk

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: inline assembler
  2003-11-05 18:04 ` Falk Hueffner
@ 2003-11-05 18:13   ` y2bismil
  2003-11-05 18:25     ` Falk Hueffner
  0 siblings, 1 reply; 9+ messages in thread
From: y2bismil @ 2003-11-05 18:13 UTC (permalink / raw)
  To: Falk Hueffner; +Cc: GCC- help

[snip]
> Just define an inline function:
> 
> static inline int times3(int x) {
>   int r;
>   asm(...);
>   return r; 
> }
> 
> -- 
> 	Falk
> 

Yeah, I was thinking about that.  But I'm a bit hesitent to do that.  I'm not
quite sure how it would affect the program.  Some parts don't want the stack
modified...so this might cause a problem with function calls.  Right now, we're
using watcom c, and they have the #pragma aux ... type statements for inline
assembler.    This allows for such things as long as u specify which register
the return value will be in.

For example, they can do the following and use it directly like a function
*********************************************
uns * CALC_POR_PTR(gaddr addr_first_par) ;
#pragma aux CALC_POR_PTR \
   = "lea eax, [ebp+4]" \
   parm nomemory [eax] \
   value [EAX] \
   modify exact nomemory [EAX] ;
*********************************************

Thanks for the help,

Yamin




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

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: inline assembler
  2003-11-05 18:01 y2bismil
@ 2003-11-05 18:04 ` Falk Hueffner
  2003-11-05 18:13   ` y2bismil
  2003-11-05 19:07 ` Kimmo Fredriksson
  1 sibling, 1 reply; 9+ messages in thread
From: Falk Hueffner @ 2003-11-05 18:04 UTC (permalink / raw)
  To: y2bismil; +Cc: GCC- help

y2bismil@engmail.uwaterloo.ca writes:

> I was wondering about inline assember.  I've been reading up quite a bit on it,
> and have noticed a common pattern to 'emulate' functions.
> ***************************************
> example from: 
> http://www.delorie.com/djgpp/doc/brennan/brennan_att_inline_djgpp.html
> ***************************************
> #define times3(arg1, arg2) \
> __asm__ ( \
>   "leal (%0,%0,2),%0" \
>   : "=r" (arg2) \
>   : "0" (arg1) );
> ***************************************
> 
> 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);

Just define an inline function:

static inline int times3(int x) {
  int r;
  asm(...);
  return r; 
}

-- 
	Falk

^ permalink raw reply	[flat|nested] 9+ messages in thread

* inline assembler
@ 2003-11-05 18:01 y2bismil
  2003-11-05 18:04 ` Falk Hueffner
  2003-11-05 19:07 ` Kimmo Fredriksson
  0 siblings, 2 replies; 9+ messages in thread
From: y2bismil @ 2003-11-05 18:01 UTC (permalink / raw)
  To: GCC- help



Hi all,

I was wondering about inline assember.  I've been reading up quite a bit on it,
and have noticed a common pattern to 'emulate' functions.
***************************************
example from: 
http://www.delorie.com/djgpp/doc/brennan/brennan_att_inline_djgpp.html
***************************************
#define times3(arg1, arg2) \
__asm__ ( \
  "leal (%0,%0,2),%0" \
  : "=r" (arg2) \
  : "0" (arg1) );
***************************************

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);

My guess is no, but I thought I'd check anyways.

Thanks,

Yamin



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

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2003-11-05 19:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2000-05-18  1:17 inline assembler Oldrich Kepka
2000-05-18  1:30 ` Alexandre Oliva
2000-05-19  7:57   ` Gary Funck
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
2003-11-05 19:23   ` y2bismil

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).