comp.lang.ada
 help / color / mirror / Atom feed
* Ada and ASM
@ 2003-09-04  7:47 luiX_
  2003-09-04 11:43 ` David C. Hoos, Sr.
                   ` (4 more replies)
  0 siblings, 5 replies; 26+ messages in thread
From: luiX_ @ 2003-09-04  7:47 UTC (permalink / raw)


Hi all, I want ot include and assembler rutine in an Ada program, does
anyone know how to do that? It will be very helpfully.

And another thing more, is there any low-level library in Ada, I would
like to do a few things that I don't know how. For example execute a
command from the operating system and getting the response from that
command.

help me please! :)

Thanks,
luiX_



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

* Re: Ada and ASM
  2003-09-04  7:47 luiX_
@ 2003-09-04 11:43 ` David C. Hoos, Sr.
  2003-09-04 15:07   ` Martin Krischik
  2003-09-06  0:22   ` Freejack
  2003-09-04 14:47 ` Martin Krischik
                   ` (3 subsequent siblings)
  4 siblings, 2 replies; 26+ messages in thread
From: David C. Hoos, Sr. @ 2003-09-04 11:43 UTC (permalink / raw)
  To: luiX_, comp.lang.ada


----- Original Message ----- 
From: "luiX_" <luixal@softhome.net>
Newsgroups: comp.lang.ada
To: <comp.lang.ada@ada.eu.org>
Sent: September 04, 2003 2:47 AM
Subject: Ada and ASM


> Hi all, I want ot include and assembler rutine in an Ada program, does
> anyone know how to do that? It will be very helpfully.

See the Adqa reference manual section on machine code insertions, and the
corresponding part of your Ada compiler's documentation.

> 
> And another thing more, is there any low-level library in Ada, I would
> like to do a few things that I don't know how. For example execute a
> command from the operating system and getting the response from that
> command.

The package at http://www.adapower.com/reuse/pipes.html
implements a thick Ada binding to the C commands allowing you to call
another program and pipe the output to your Ada program, and/or pipe input
from your Ada program.

> 
> help me please! :)
> 
> Thanks,
> luiX_
> _______________________________________________
> comp.lang.ada mailing list
> comp.lang.ada@ada.eu.org
> http://ada.eu.org/mailman/listinfo/comp.lang.ada
> 
> 




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

* Re: Ada and ASM
  2003-09-04  7:47 luiX_
  2003-09-04 11:43 ` David C. Hoos, Sr.
@ 2003-09-04 14:47 ` Martin Krischik
  2003-09-04 15:08 ` Martin Krischik
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 26+ messages in thread
From: Martin Krischik @ 2003-09-04 14:47 UTC (permalink / raw)
  To: luiX_

<verï¿œffentlicht & per Mail versendet>

luiX_ wrote:

> Hi all, I want ot include and assembler rutine in an Ada program, does
> anyone know how to do that? It will be very helpfully.
> 
> And another thing more, is there any low-level library in Ada, I would
> like to do a few things that I don't know how. For example execute a
> command from the operating system and getting the response from that
> command.

AdaCL (http://adacl.sourceforge.net/) has a low level library for OS/2,
Windows and Linux.

With Regards

Martin

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com




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

* Re: Ada and ASM
  2003-09-04 11:43 ` David C. Hoos, Sr.
@ 2003-09-04 15:07   ` Martin Krischik
  2003-09-06  0:22   ` Freejack
  1 sibling, 0 replies; 26+ messages in thread
From: Martin Krischik @ 2003-09-04 15:07 UTC (permalink / raw)


David C. Hoos, Sr. wrote:

 > ----- Original Message -----
> From: "luiX_" <luixal@softhome.net>
> Newsgroups: comp.lang.ada
> To: <comp.lang.ada@ada.eu.org>
> Sent: September 04, 2003 2:47 AM
> Subject: Ada and ASM

>> And another thing more, is there any low-level library in Ada, I would
>> like to do a few things that I don't know how. For example execute a
>> command from the operating system and getting the response from that
>> command.
 
> The package at http://www.adapower.com/reuse/pipes.html
> implements a thick Ada binding to the C commands allowing you to call
> another program and pipe the output to your Ada program, and/or pipe input
> from your Ada program.

I would not realy consider it a "thick" binding. Besides, it used the C
function popen () and that has a distinct disadvantage: you can either read
or write from the external program you can't to both.

Personaly I think popen () if a design mistake - espacialy when you see the
source: It open both a read and write pipe and then just throws away the
one of them.

With Regards

Martin

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com




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

* Re: Ada and ASM
  2003-09-04  7:47 luiX_
  2003-09-04 11:43 ` David C. Hoos, Sr.
  2003-09-04 14:47 ` Martin Krischik
@ 2003-09-04 15:08 ` Martin Krischik
  2003-09-04 19:31 ` Leif Holmgren
  2003-09-05  5:46 ` Simon Wright
  4 siblings, 0 replies; 26+ messages in thread
From: Martin Krischik @ 2003-09-04 15:08 UTC (permalink / raw)


luiX_ wrote:

> Hi all, I want ot include and assembler rutine in an Ada program, does
> anyone know how to do that? It will be very helpfully.
> 
> And another thing more, is there any low-level library in Ada, I would
> like to do a few things that I don't know how. For example execute a
> command from the operating system and getting the response from that
> command.

AdaCL (http://adacl.sourceforge.net/) has a low level library for OS/2,
Windows and Linux.

With Regards

Martin

-- 
mailto://krischik@users.sourceforge.net
http://www.ada.krischik.com




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

* Re: Ada and ASM
  2003-09-04  7:47 luiX_
                   ` (2 preceding siblings ...)
  2003-09-04 15:08 ` Martin Krischik
@ 2003-09-04 19:31 ` Leif Holmgren
  2003-09-05  2:42   ` Robert C. Leif
                     ` (2 more replies)
  2003-09-05  5:46 ` Simon Wright
  4 siblings, 3 replies; 26+ messages in thread
From: Leif Holmgren @ 2003-09-04 19:31 UTC (permalink / raw)


luiX_ wrote:
> Hi all, I want ot include and assembler rutine in an Ada program, does
> anyone know how to do that? It will be very helpfully.

As someone else said, Ada RM and Compiler manuals are the first steps. 
Note that if you are using GNAT, most things are in the gcc documentation!

If you manage to decode the gcc manual, please write something useful 
down on how it should be done.

I'm currently also trying to include some asm code in my program (using 
Gnat). I have totally failed to get the interfacing part going. I know 
my statement sequence is correct since I first coded it using Borland 
Delphi's inline assembler. I guess I will end up wrapping my code in a DLL.

/Leif




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

* RE: Ada and ASM
  2003-09-04 19:31 ` Leif Holmgren
@ 2003-09-05  2:42   ` Robert C. Leif
  2003-09-05 21:32   ` Jerry van Dijk
  2003-09-23 10:45   ` Jacob Sparre Andersen
  2 siblings, 0 replies; 26+ messages in thread
From: Robert C. Leif @ 2003-09-05  2:42 UTC (permalink / raw)
  To: Comp. Lang. Ada

A long time ago, someone I believe it was at Whitesmiths wrote an assembler
in the syntax of a higher level language. I can not understand why we need
two different syntaxes for assembler and Ada. I would hope that someone
would create an assembler that was completely written in Ada with Ada
syntax. Although the individual commands of microprocessors differ, a common
syntax can be used to describe their commands.
Bob Leif
Robert C. Leif, Ph.D.
Email rleif@rleif.com

-----Original Message-----
From: Leif Holmgren [mailto:nobody@nowhere.com] 
Sent: Thursday, September 04, 2003 12:32 PM
To: comp.lang.ada@ada.eu.org
Subject: Re: Ada and ASM

luiX_ wrote:
> Hi all, I want ot include and assembler rutine in an Ada program, does
> anyone know how to do that? It will be very helpfully.

As someone else said, Ada RM and Compiler manuals are the first steps. 
Note that if you are using GNAT, most things are in the gcc documentation!

If you manage to decode the gcc manual, please write something useful 
down on how it should be done.

I'm currently also trying to include some asm code in my program (using 
Gnat). I have totally failed to get the interfacing part going. I know 
my statement sequence is correct since I first coded it using Borland 
Delphi's inline assembler. I guess I will end up wrapping my code in a DLL.

/Leif





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

* Re: Ada and ASM
  2003-09-04  7:47 luiX_
                   ` (3 preceding siblings ...)
  2003-09-04 19:31 ` Leif Holmgren
@ 2003-09-05  5:46 ` Simon Wright
  2003-09-05 15:44   ` Robert C. Leif
  4 siblings, 1 reply; 26+ messages in thread
From: Simon Wright @ 2003-09-05  5:46 UTC (permalink / raw)


luixal@softhome.net (luiX_) writes:

> Hi all, I want ot include and assembler rutine in an Ada program,
> does anyone know how to do that? It will be very helpfully.

If you are using GNAT, see
http://gcc.gnu.org/onlinedocs/gnat_ug_unx/Inline-Assembler.html#Inline%20Assembler



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

* RE: Ada and ASM
  2003-09-05  5:46 ` Simon Wright
@ 2003-09-05 15:44   ` Robert C. Leif
  0 siblings, 0 replies; 26+ messages in thread
From: Robert C. Leif @ 2003-09-05 15:44 UTC (permalink / raw)
  To: 'Simon Wright', comp.lang.ada

Although GNAT has moved in this direction, it appears to be far from a true
Ada syntax representation. 
From:
http://gcc.gnu.org/onlinedocs/gnat_ug_unx/The-Volatile-Parameter.html#The%20
Volatile%20Parameter
Asm ("movl %0, %%ebx" & LF & HT &
          "movl %%ebx, %1",
          Inputs   => Unsigned_32'Asm_Input  ("g", Var_In),
          Outputs  => Unsigned_32'Asm_Output ("=g", Var_Out),
          Clobber  => "ebx",
          Volatile => True);
The actual Asm statement still is a quoted string. It is not Ada syntax.
Bob Leif
Robert C. Leif, Ph.D.
Email rleif@rleif.com

-----Original Message-----
From: Simon Wright [mailto:simon@pushface.org] 
Sent: Thursday, September 04, 2003 10:47 PM
To: comp.lang.ada@ada.eu.org
Subject: Re: Ada and ASM

luixal@softhome.net (luiX_) writes:

> Hi all, I want ot include and assembler rutine in an Ada program,
> does anyone know how to do that? It will be very helpfully.

If you are using GNAT, see
http://gcc.gnu.org/onlinedocs/gnat_ug_unx/Inline-Assembler.html#Inline%20Ass
embler




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

* Re: Ada and ASM
       [not found] <E19vIlZ-0002mO-Fg@punt-3.mail.demon.net>
@ 2003-09-05 19:09 ` Simon Wright
  2003-09-05 21:38   ` Jerry van Dijk
  0 siblings, 1 reply; 26+ messages in thread
From: Simon Wright @ 2003-09-05 19:09 UTC (permalink / raw)
  To: rleif; +Cc: comp.lang.ada

> From: "Robert C. Leif" <rleif@rleif.com>

> Although GNAT has moved in this direction, it appears to be far from a true
> Ada syntax representation. 
> From:
> http://gcc.gnu.org/onlinedocs/gnat_ug_unx/The-Volatile-Parameter.html#The%20
> Volatile%20Parameter
> Asm ("movl %0, %%ebx" & LF & HT &
>           "movl %%ebx, %1",
>           Inputs   => Unsigned_32'Asm_Input  ("g", Var_In),
>           Outputs  => Unsigned_32'Asm_Output ("=g", Var_Out),
>           Clobber  => "ebx",
>           Volatile => True);
> The actual Asm statement still is a quoted string. It is not Ada syntax.

I do not understand how it could possibly "[be] Ada syntax".

OP wanted to include an asm *routine*, I think, so perhaps what is
wanted instead is a pragma Import (Asm, ...)? (if suoported). You
could always write the asm routine using C calling conventions,
whatever they are (if different from asm) and use pragma Import (C,
...).

As always, and as others have said, RTFM!



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

* Re: Ada and ASM
  2003-09-04 19:31 ` Leif Holmgren
  2003-09-05  2:42   ` Robert C. Leif
@ 2003-09-05 21:32   ` Jerry van Dijk
  2003-09-23 10:45   ` Jacob Sparre Andersen
  2 siblings, 0 replies; 26+ messages in thread
From: Jerry van Dijk @ 2003-09-05 21:32 UTC (permalink / raw)



Leif Holmgren <nobody@nowhere.com> writes:

> I'm currently also trying to include some asm code in my program (using
> Gnat). I have totally failed to get the interfacing part going. I know my
> statement sequence is correct since I first coded it using Borland Delphi's
> inline assembler. I guess I will end up wrapping my code in a DLL.

If you have a recent version of GNAT, the info is in the user manual. Perhaps
easier is my old tutorial which you can find at adapower:

http://www.adapower.com/articles/gnatasm/index.html

-- 
--  Jerry van Dijk, Leiden, Holland 
--  Note that email address is invalid



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

* Re: Ada and ASM
  2003-09-05 19:09 ` Simon Wright
@ 2003-09-05 21:38   ` Jerry van Dijk
  2003-09-06  6:11     ` David Marceau
  0 siblings, 1 reply; 26+ messages in thread
From: Jerry van Dijk @ 2003-09-05 21:38 UTC (permalink / raw)



Simon Wright <simon@pushface.org> writes:

> > Volatile%20Parameter
> > Asm ("movl %0, %%ebx" & LF & HT &
> >           "movl %%ebx, %1",
> >           Inputs   => Unsigned_32'Asm_Input  ("g", Var_In),
> >           Outputs  => Unsigned_32'Asm_Output ("=g", Var_Out),
> >           Clobber  => "ebx",
> >           Volatile => True);
> > The actual Asm statement still is a quoted string. It is not Ada syntax.
> 
> I do not understand how it could possibly "[be] Ada syntax".
> 
> OP wanted to include an asm *routine*, I think, so perhaps what is
> wanted instead is a pragma Import (Asm, ...)? (if suoported).

No, you can include a ASM routine very easily this way (although, yes, one
does need to actually read the documentation first :-).

Note that this has three big advantages over a separately assembled function:
1) no need to use non Ada tools
2) easy access to other Ada objects
3) optimizer can help

-- 
--  Jerry van Dijk, Leiden, Holland 
--  Note that email address is invalid



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

* RE: Ada and ASM
       [not found] <200309051909.h85J9Flb002351@smaug.pushface.org>
@ 2003-09-06  0:15 ` Robert C. Leif
  0 siblings, 0 replies; 26+ messages in thread
From: Robert C. Leif @ 2003-09-06  0:15 UTC (permalink / raw)
  To: 'Simon Wright'; +Cc: comp.lang.ada

I want to replace the ASM call by Ada syntax. Assuming one had a package
Asm, then I would like something like the following

A,B:Asm.register_32;
A:=10_000;
Asm.Move(From=>A To=>B);

The assembly operations are expressed as true Ada subprograms.
Bob Leif
Robert C. Leif, Ph.D.
Email rleif@rleif.com

-----Original Message-----
From: Simon Wright [mailto:simon@pushface.org] 
Sent: Friday, September 05, 2003 12:09 PM
To: rleif@rleif.com
Cc: comp.lang.ada@ada.eu.org
Subject: Re: Ada and ASM

> From: "Robert C. Leif" <rleif@rleif.com>

> Although GNAT has moved in this direction, it appears to be far from a
true
> Ada syntax representation. 
> From:
>
http://gcc.gnu.org/onlinedocs/gnat_ug_unx/The-Volatile-Parameter.html#The%20
> Volatile%20Parameter
> Asm ("movl %0, %%ebx" & LF & HT &
>           "movl %%ebx, %1",
>           Inputs   => Unsigned_32'Asm_Input  ("g", Var_In),
>           Outputs  => Unsigned_32'Asm_Output ("=g", Var_Out),
>           Clobber  => "ebx",
>           Volatile => True);
> The actual Asm statement still is a quoted string. It is not Ada syntax.

I do not understand how it could possibly "[be] Ada syntax".

OP wanted to include an asm *routine*, I think, so perhaps what is
wanted instead is a pragma Import (Asm, ...)? (if suoported). You
could always write the asm routine using C calling conventions,
whatever they are (if different from asm) and use pragma Import (C,
...).

As always, and as others have said, RTFM!




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

* Re: Ada and ASM
  2003-09-04 11:43 ` David C. Hoos, Sr.
  2003-09-04 15:07   ` Martin Krischik
@ 2003-09-06  0:22   ` Freejack
  2003-09-06  2:18     ` Jerry van Dijk
  1 sibling, 1 reply; 26+ messages in thread
From: Freejack @ 2003-09-06  0:22 UTC (permalink / raw)


On Thu, 04 Sep 2003 07:43:36 -0400, David C. Hoos, Sr. wrote:


> ----- Original Message -----
> From: "luiX_" <luixal@softhome.net>
> Newsgroups: comp.lang.ada
> To: <comp.lang.ada@ada.eu.org>
> Sent: September 04, 2003 2:47 AM
> Subject: Ada and ASM
> 
> 
>> Hi all, I want ot include and assembler rutine in an Ada program, does
>> anyone know how to do that? It will be very helpfully.
 
> See the Adqa reference manual section on machine code insertions, and
> the corresponding part of your Ada compiler's documentation.

As far as I can tell the GNAT system expects everything to be in GAS (Gnu
Assembler) syntax and it expects the Assembler to be GAS.

I've not found any documentation anywhere explaining how to use something
like Nasm(Netwide Assembler), Tasm(Turbo Assembler), Fasm, ect... or
anything besides Gas with GNAT.

Dont misunderstand me. GNAT is awsome. But it seems a little Amish in
this respect. I could direct the backend GCC to link in my Nasm code, but
then that means usually dicking with C calling conventions in tedium.

Any pointers?

Freejack



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

* Re: Ada and ASM
  2003-09-06  0:22   ` Freejack
@ 2003-09-06  2:18     ` Jerry van Dijk
  2003-09-06 12:59       ` Jeffrey Creem
  0 siblings, 1 reply; 26+ messages in thread
From: Jerry van Dijk @ 2003-09-06  2:18 UTC (permalink / raw)



Freejack <user@nospam.com> writes:

> As far as I can tell the GNAT system expects everything to be in GAS (Gnu
> Assembler) syntax and it expects the Assembler to be GAS.

To be precise, GAS is only a front-end for the real assembler 'as'. 
The idea of GAS was to make it a little easier to write assembler by hand, as
'as' is really meant to assemble machine generated code.

For the GNU system (which includes gcc and thus GNAT) 'as' is the standard
assembler on all platforms.

> I've not found any documentation anywhere explaining how to use something
> like Nasm(Netwide Assembler), Tasm(Turbo Assembler), Fasm, ect... or
> anything besides Gas with GNAT

You are reversing reality :-) You can link any assembled object code with gcc
(and thus GNAT) that you like, provided that the assembler you use generates
object code in the correct format. Which format that is depends on the
platform you are using. Of the x86 specific assemblers you mention I think
that only NASM is capable (under linux and win32) to generate correct object 
code (as is BTW 32-bit MASM, under Win32). If you want to use TASM, ask 
Borland to have it create the correct object code for your pupose. As for 
FASM, well...

But why is this a problem ? Simply convert your NASM code to AT&T syntax, and
assemble it with GAS. For the x86 this conversion is fairly trival, and there
are some tools out there to help.

> Dont misunderstand me. GNAT is awsome. But it seems a little Amish in
> this respect. I could direct the backend GCC to link in my Nasm code, but
> then that means usually dicking with C calling conventions in tedium.

Yes, of course, what else would you expect ? NASM does not provide you with an
gcc compatible Ada calling convention (or a COBOL convention, or a FORTRAN
convention, or a...). If you want this, ask the NASM people to provide this 
for you :-) The same goes for any other assembler I am aware of. 

An alternative is to use GNAT's inline assembler facility, which makes
interfacing to Ada a breeze. 

If you do not want to do this for some reason, simple write the subprogram 
definition (and any variable you need) in Ada with a null body, and have it 
generate assembler for it (see my tutorial on how to do this). Then either 
fill in the body with you own code converted to AT&T syntax, or use the 
generated assembler code as an template on how to interface to Ada directly
from NASM.

Hope this helps,
Jerry.

-- 
--  Jerry van Dijk, Leiden, Holland 
--  Note that email address is invalid



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

* Re: Ada and ASM
  2003-09-05 21:38   ` Jerry van Dijk
@ 2003-09-06  6:11     ` David Marceau
  2003-09-07  7:18       ` sk
  0 siblings, 1 reply; 26+ messages in thread
From: David Marceau @ 2003-09-06  6:11 UTC (permalink / raw)


Jerry van Dijk wrote:
> 
> Simon Wright <simon@pushface.org> writes:
> 
> > > Volatile%20Parameter
> > > Asm ("movl %0, %%ebx" & LF & HT &
> > >           "movl %%ebx, %1",
> > >           Inputs   => Unsigned_32'Asm_Input  ("g", Var_In),
> > >           Outputs  => Unsigned_32'Asm_Output ("=g", Var_Out),
> > >           Clobber  => "ebx",
> > >           Volatile => True);
> > > The actual Asm statement still is a quoted string. It is not Ada syntax.
> >
> > I do not understand how it could possibly "[be] Ada syntax".
> >
> > OP wanted to include an asm *routine*, I think, so perhaps what is
> > wanted instead is a pragma Import (Asm, ...)? (if suoported).
> 
> No, you can include a ASM routine very easily this way (although, yes, one
> does need to actually read the documentation first :-).
> 
> Note that this has three big advantages over a separately assembled function:
> 1) no need to use non Ada tools
> 2) easy access to other Ada objects
> 3) optimizer can help
> 
> --
> --  Jerry van Dijk, Leiden, Holland
> --  Note that email address is invalid
1)I think Mr. van Dijk's inline assembler in ada tutorial(on adapower
and part of ACT/GNAT docs) is the most straightforward and most fluid. 
Lots of gnu.org site borrows from your doc but IMHO the flow changed and
to get a better picture I do suggest to look at both the adapower
version and also the gnu.org version of the documentation.  

2)Check out http://studwww.rug.ac.be/~fcorneli/eduos
The link doesn't seem to be working at the moment but the document is
called:
"Making plain binary  
files using a C compiler (i386+) Cornelis Frank
<Frank.Cornelis@rug.ac.be> April 27, 2001
"
The actual doc explains much about generating assembler files from C
files and the helper tools around all this.
It also mentions a bit about nasm for those who were looking for it.  It
is an excellent supplemental to the ada inline assembler docs.

3)Last but not least, Mr. Simon Knipe <sknipe@ktc.com> has made a
wonderful tutorial to make an Ada OS:
http://www.ktc.com/~sknipe/EOSA.html
I suggest examining its sources showing the usage of nasm and Ada
bridging them together using "pragma import" to make an OS.
There are a lot of cool tidbits in here that could equally apply to
in-line ada assembler.
One of the people on this thread was looking for pragma import stuff
using nasm well here it is :)

4)A bit off topic but still related because it does talk about getting
closer to metal.(spec'ing to cpu/dsp/controller chips)
It is also a great place demonstrating ada's strong concurrency
mechanisms with sources.
http://cs.anu.edu.au/student/comp4710/Lectures/RTES.book.e.pdf
http://cs.anu.edu.au/student/comp4710/Level-0/Sources.html

I hope this helps :)

Cheers,
David Marceau



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

* Re: Ada and ASM
       [not found] <E19vQkV-0006EH-Ek@punt-3.mail.demon.net>
@ 2003-09-06  7:25 ` Simon Wright
  2003-09-06 13:14   ` Marin David Condic
  2003-09-06 15:25   ` Wes Groleau
  0 siblings, 2 replies; 26+ messages in thread
From: Simon Wright @ 2003-09-06  7:25 UTC (permalink / raw)
  To: rleif; +Cc: comp.lang.ada

> I want to replace the ASM call by Ada syntax. Assuming one had a
> package Asm, then I would like something like the following
> 
> A,B:Asm.register_32;
> A:=10_000;
> Asm.Move(From=>A To=>B);
> 
> The assembly operations are expressed as true Ada subprograms.

All very well if all you wanted to do was move things about. But
machines have all sorts of features, not all of which have
counterparts on each architecture to be supported. What about reading
the high-resolution clock? (rdtsc on Pentium, mftb on PowerPC).

   function Clock return Time is
      type Half is (Low, High);
      Lower, Upper : Interfaces.Unsigned_32;
      Results : array (Half) of Interfaces.Unsigned_32;
      Result : Time;
      for Result'Address use Results (Low)'Address;
   begin
      System.Machine_Code.Asm
        ("rdtsc" & ASCII.LF & ASCII.HT &
           "movl %%eax, %0"& ASCII.LF & ASCII.HT &
           "movl %%edx, %1",
         Outputs => (Interfaces.Unsigned_32'Asm_Output ("=g", Lower),
                     Interfaces.Unsigned_32'Asm_Output ("=g", Upper)),
         Clobber => "eax, edx");
      Results := (Low => Lower, High => Upper);
      return Result;
   end Clock;

is an Intel version, the PPC version (which I can't post) is quite
different in structure. For a start, you have to read the timestamp in
two bites! (on 32-bit implementations).

The major reason for using asm must be precisely to accommodate these
sorts of differences.



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

* Re: Ada and ASM
  2003-09-06  2:18     ` Jerry van Dijk
@ 2003-09-06 12:59       ` Jeffrey Creem
  2003-09-06 15:33         ` Wes Groleau
  2003-09-06 17:16         ` Jerry van Dijk
  0 siblings, 2 replies; 26+ messages in thread
From: Jeffrey Creem @ 2003-09-06 12:59 UTC (permalink / raw)



"Jerry van Dijk" <somename@nospam.demon.nl> wrote in message
news:m2ad9imzh2.fsf@jvdsys.demon.nl...
>
> Freejack <user@nospam.com> writes:
>
> > As far as I can tell the GNAT system expects everything to be in GAS
(Gnu
> > Assembler) syntax and it expects the Assembler to be GAS.
>
> To be precise, GAS is only a front-end for the real assembler 'as'.
> The idea of GAS was to make it a little easier to write assembler by hand,
as
> 'as' is really meant to assemble machine generated code.
>
> For the GNU system (which includes gcc and thus GNAT) 'as' is the standard
> assembler on all platforms.


I don't think this really is the right way to be precise here.

The GNU Assembler, which people often call GAS gets built and installed
(typically) as a binary
called as.  GAS is not a front-end for a real assembler. GAS is a real
assembler. Calling GAS essentially
a front-end or preprocessor (which is essentially the feeling one gets from
the above post...although certainly
not the words of the above post) seems a little misleading.







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

* Re: Ada and ASM
  2003-09-06  7:25 ` Ada and ASM Simon Wright
@ 2003-09-06 13:14   ` Marin David Condic
  2003-09-06 15:25   ` Wes Groleau
  1 sibling, 0 replies; 26+ messages in thread
From: Marin David Condic @ 2003-09-06 13:14 UTC (permalink / raw)


True, it would be difficult to have some sort of "full-up" Ada syntax 
for assembler that was anywhere near portable across all machines. 
Unless you simply got to the point where you're compiling Ada anyway, so 
why bother? ;-)

However, I recall at least one Ada compiler that essentially defined 
something that looked like a discriminated record for assembler 
instructions and your assembler routines effectively looked like a set 
of agregates for the discriminated record where each aggregate 
represented the machine instruction you wanted. That was pretty much an 
"Ada Syntax" of sorts. Perhaps something along those lines with some 
semi-standard "macro-like" capabilities would be a good thing. (For 
example, if there were some flavor of "if" or "loop" statements that 
automagically expanded out into the corresponding machine instructions, 
that would be helpful and about all you'd need when you are dipping into 
assembler.)

MDC


Simon Wright wrote:
> 
> 
> All very well if all you wanted to do was move things about. But
> machines have all sorts of features, not all of which have
> counterparts on each architecture to be supported. What about reading
> the high-resolution clock? (rdtsc on Pentium, mftb on PowerPC).
> 
>    function Clock return Time is
>       type Half is (Low, High);
>       Lower, Upper : Interfaces.Unsigned_32;
>       Results : array (Half) of Interfaces.Unsigned_32;
>       Result : Time;
>       for Result'Address use Results (Low)'Address;
>    begin
>       System.Machine_Code.Asm
>         ("rdtsc" & ASCII.LF & ASCII.HT &
>            "movl %%eax, %0"& ASCII.LF & ASCII.HT &
>            "movl %%edx, %1",
>          Outputs => (Interfaces.Unsigned_32'Asm_Output ("=g", Lower),
>                      Interfaces.Unsigned_32'Asm_Output ("=g", Upper)),
>          Clobber => "eax, edx");
>       Results := (Low => Lower, High => Upper);
>       return Result;
>    end Clock;
> 
> is an Intel version, the PPC version (which I can't post) is quite
> different in structure. For a start, you have to read the timestamp in
> two bites! (on 32-bit implementations).
> 
> The major reason for using asm must be precisely to accommodate these
> sorts of differences.


-- 
======================================================================
Marin David Condic
I work for: http://www.belcan.com/
My project is: http://www.jast.mil/

Send Replies To: m c o n d i c @ a c m . o r g

     "In general the art of government consists in taking as
     much money as possible from one class of citizens to give
     to the other."

         --  Voltaire
======================================================================




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

* Re: Ada and ASM
  2003-09-06  7:25 ` Ada and ASM Simon Wright
  2003-09-06 13:14   ` Marin David Condic
@ 2003-09-06 15:25   ` Wes Groleau
  1 sibling, 0 replies; 26+ messages in thread
From: Wes Groleau @ 2003-09-06 15:25 UTC (permalink / raw)


>>I want to replace the ASM call by Ada syntax. Assuming one had a
>>package Asm, then I would like something like the following
>>
>>A,B:Asm.register_32;
>>A:=10_000;
>>Asm.Move(From=>A To=>B);
>>
>>The assembly operations are expressed as true Ada subprograms.

Are you saying you want every opcode to have
the overhead of a subprogram call?  Or are you
just looking for a more Ada-like syntax for
the special stuff?

Either way, you should read about package
System.Machine_Code in RM95 13.8

-- 
Wes Groleau
   "Grant me the serenity to accept those I cannot change;
    the courage to change the one I can;
    and the wisdom to know it's me."
                                -- unknown




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

* Re: Ada and ASM
  2003-09-06 12:59       ` Jeffrey Creem
@ 2003-09-06 15:33         ` Wes Groleau
  2003-09-06 17:11           ` Jerry van Dijk
  2003-09-06 17:16         ` Jerry van Dijk
  1 sibling, 1 reply; 26+ messages in thread
From: Wes Groleau @ 2003-09-06 15:33 UTC (permalink / raw)


>>>As far as I can tell the GNAT system expects everything
> to be in GAS (Gnu Assembler) syntax and it expects the
 >> Assembler to be GAS.
>>
>>To be precise, GAS is only a front-end for the real assembler 'as'.
>>The idea of GAS was to make it a little easier to write assembler by hand,

When compiling Ada or C or ?, an intermediate stage
is assembly language.  This is passed to whatever assembler
the installation is configured to use.  On Solaris,
'gas' and 'as' are two independent assemblers, and _either_
can be called by the compiler.  And it worked fine
when 'gas' was not installed.

For ASN/machine code insertions, IF there are any syntax
differences, I would _speculate_ that you have to use
the one that works with the assembler you will be using.

-- 
Wes Groleau

Is it an on-line compliment to call someone a Net Wit ?




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

* Re: Ada and ASM
  2003-09-06 15:33         ` Wes Groleau
@ 2003-09-06 17:11           ` Jerry van Dijk
  2003-09-07  4:02             ` Wes Groleau
  0 siblings, 1 reply; 26+ messages in thread
From: Jerry van Dijk @ 2003-09-06 17:11 UTC (permalink / raw)



Wes Groleau <groleau@freeshell.org> writes:

> the installation is configured to use.  On Solaris,
> 'gas' and 'as' are two independent assemblers, and _either_
> can be called by the compiler.  And it worked fine
> when 'gas' was not installed.

I am using linux (mdk 9.1) right now and much to my supprise:

        [jerry@jvdsys jerry]$ gas
        bash: gas: command not found
        [jerry@jvdsys jerry]$ ll /usr/bin/gas
        ls: /usr/bin/gas: No such file or directory
        [jerry@jvdsys jerry]$ ll /usr/bin/as
        -rwxr-xr-x    1 root     root       256684 Feb 15  2003 /usr/bin/as*

No gas, only as.

-- 
--  Jerry van Dijk, Leiden, Holland 
--  Note that email address is invalid



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

* Re: Ada and ASM
  2003-09-06 12:59       ` Jeffrey Creem
  2003-09-06 15:33         ` Wes Groleau
@ 2003-09-06 17:16         ` Jerry van Dijk
  1 sibling, 0 replies; 26+ messages in thread
From: Jerry van Dijk @ 2003-09-06 17:16 UTC (permalink / raw)



"Jeffrey Creem" <jeff@thecreems.com> writes:

> > To be precise, GAS is only a front-end for the real assembler 'as'.

> I don't think this really is the right way to be precise here.

> The GNU Assembler, which people often call GAS gets built and installed
> (typically) as a binary
> called as.  GAS is not a front-end for a real assembler. GAS is a real
> assembler. Calling GAS essentially
> a front-end or preprocessor (which is essentially the feeling one gets from
> the above post...although certainly
> not the words of the above post) seems a little misleading.

I checked again and you are certainly correct as to what the current manual
says. I am pretty sure it didn't use to be like this, but I am not going to
install an old binutils to find out (but maybe someone happen to have one
installed ?). Otherwise I might just be aging prematurely :-)

-- 
--  Jerry van Dijk, Leiden, Holland 
--  Note that email address is invalid



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

* Re: Ada and ASM
  2003-09-06 17:11           ` Jerry van Dijk
@ 2003-09-07  4:02             ` Wes Groleau
  0 siblings, 0 replies; 26+ messages in thread
From: Wes Groleau @ 2003-09-07  4:02 UTC (permalink / raw)


Jerry van Dijk wrote:
> I am using linux (mdk 9.1) right now and much to my supprise:
> 
>         [snip]
> 
> No gas, only as.

Well, if you call it with -v what does it say?

In the case of Linux, I would not be surprised
to find that 'gas' is installed with the name 'as'

-- 
Wes Groleau
Genealogical Lookups:  http://groleau.freeshell.org/ref/lookups.html




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

* Re: Ada and ASM
  2003-09-06  6:11     ` David Marceau
@ 2003-09-07  7:18       ` sk
  0 siblings, 0 replies; 26+ messages in thread
From: sk @ 2003-09-07  7:18 UTC (permalink / raw)
  To: comp.lang.ada

Hi David :-),

davidmarceau@sympatico.ca:
 > 3)Last ... http://www.ktc.com/~sknipe/EOSA.html ...

I have just updated my home page, so access through
"http://www.ktc.com/~sknipe" and follow the links.

Slight correction, my goal was to produce a bootable
Ada main for others to play with rather than create
a pretender in the OS sweepstakes.

... also, the term "Ada OS" is more correctly associated with
the AdaOS group (the URL I have seems to be dead) which had
a stated intention of creating a new OS using Ada; a group I have
no affiliation with.

... also, the most current document doesn't use NASM, only
gas/as.

... besides, the OP seemed to be interested in the inline
assembly, not linking. Seems as if the OP has disappeared
from the thread anyway :-).

-- 
-------------------------------------------------
-- Merge vertically for real address
--
--     s n p @ t . o
--      k i e k c c m
-------------------------------------------------




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

* Re: Ada and ASM
  2003-09-04 19:31 ` Leif Holmgren
  2003-09-05  2:42   ` Robert C. Leif
  2003-09-05 21:32   ` Jerry van Dijk
@ 2003-09-23 10:45   ` Jacob Sparre Andersen
  2 siblings, 0 replies; 26+ messages in thread
From: Jacob Sparre Andersen @ 2003-09-23 10:45 UTC (permalink / raw)


Leif Holmgren wrote:

> I'm currently also trying to include some asm code in my program (using 
> Gnat). I have totally failed to get the interfacing part going. I know 
> my statement sequence is correct since I first coded it using Borland 
> Delphi's inline assembler. I guess I will end up wrapping my code in a DLL.

IIRC the old Borland Pascal compilers (an probably also Delphi/Kylix)
used Intel assembler syntax whereas GNAT uses GNU assembler syntax.

So you may have to start rewriting your assembler code.

Jacob
-- 
"Preserve wildlife, pickle a duck."




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

end of thread, other threads:[~2003-09-23 10:45 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <E19vQkV-0006EH-Ek@punt-3.mail.demon.net>
2003-09-06  7:25 ` Ada and ASM Simon Wright
2003-09-06 13:14   ` Marin David Condic
2003-09-06 15:25   ` Wes Groleau
     [not found] <200309051909.h85J9Flb002351@smaug.pushface.org>
2003-09-06  0:15 ` Robert C. Leif
     [not found] <E19vIlZ-0002mO-Fg@punt-3.mail.demon.net>
2003-09-05 19:09 ` Simon Wright
2003-09-05 21:38   ` Jerry van Dijk
2003-09-06  6:11     ` David Marceau
2003-09-07  7:18       ` sk
2003-09-04  7:47 luiX_
2003-09-04 11:43 ` David C. Hoos, Sr.
2003-09-04 15:07   ` Martin Krischik
2003-09-06  0:22   ` Freejack
2003-09-06  2:18     ` Jerry van Dijk
2003-09-06 12:59       ` Jeffrey Creem
2003-09-06 15:33         ` Wes Groleau
2003-09-06 17:11           ` Jerry van Dijk
2003-09-07  4:02             ` Wes Groleau
2003-09-06 17:16         ` Jerry van Dijk
2003-09-04 14:47 ` Martin Krischik
2003-09-04 15:08 ` Martin Krischik
2003-09-04 19:31 ` Leif Holmgren
2003-09-05  2:42   ` Robert C. Leif
2003-09-05 21:32   ` Jerry van Dijk
2003-09-23 10:45   ` Jacob Sparre Andersen
2003-09-05  5:46 ` Simon Wright
2003-09-05 15:44   ` Robert C. Leif

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