comp.lang.ada
 help / color / mirror / Atom feed
From: Samuel Tardieu <sam@ada.eu.org>
To: Frederic Deshaies <Frederic.Deshaies@wanadoo.fr>
Subject: Re: Ada and assembler
Date: 1997/09/18
Date: 1997-09-18T00:00:00+00:00	[thread overview]
Message-ID: <qw67mceehbl.fsf@esmeralda.enst.fr> (raw)
In-Reply-To: 341F0106.404@wanadoo.fr


>>>>> "Frederic" == Frederic Deshaies <Frederic.Deshaies@wanadoo.fr> writes:

Frederic> Hello, I would like to know how i can put assembler
Frederic> instructions in an Ada program ?

If you are using GNAT, then you can use the System.Machine_Code
package just as you use "asm" directive in C with GCC. Here is an
example coming from a Sparc/Solaris-specific file of the GNAT library: 

      function Get_G7 return Interfaces.C.Unsigned;
      pragma Inline (Get_G7);

      ------------
      -- Get_G7 --
      ------------

      function Get_G7 return Interfaces.C.Unsigned is
         Result : Interfaces.C.Unsigned;
      begin
         Asm ("mov %%g7,%0", Interfaces.C.Unsigned'Asm_Output ("=r", Result));
         return Result;
      end Get_G7;

Note that this is a very powerful and efficient mechanism, because in
this example if you use for example:

      if Get_G7 = Some_Value then

then there will be no function call (thanks to inlining) and the code
used to retrieve the value of the G7 register will be scheduled
efficiently by the GCC backend.

Of course, if you are using another target, you have to put i386+
opcodes in your Asm statements.

The best source of information for assembly inlining in GNAT is the
GNAT documentation and the GCC documentation (the first one describes
how you can use from Ada the features describe in the latter).

  Sam
-- 
Samuel Tardieu -- sam@ada.eu.org




  reply	other threads:[~1997-09-18  0:00 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
1997-09-16  0:00 Ada and assembler Frederic Deshaies
1997-09-18  0:00 ` Samuel Tardieu [this message]
1997-09-19  0:00 ` Robert Dewar
  -- strict thread matches above, loose matches on Subject: below --
1997-09-17  0:00 ADA " Frederic Deshaies
2002-03-31 13:10 Ada and Assembler Henrik Quintel
2002-03-31 13:34 ` David C. Hoos, Sr.
2002-03-31 14:02 ` Dr. Michael Paus
2002-03-31 21:09 ` John R. Strohm
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox