From: Russ Urquhart
Subject: Newbie - Call assembly language function from Lisp?
Date: 
Message-ID: <381F224F.5C7288B1@aud.alcatel.com>
As the subject says. I'm getting into Lisp, but was wondering if there
was a way to call assembly routines that i've written?

Ideally this would be on an Intel machine, but not necessarily
restricted to that architecture alone.

Any help is greatly appreciated!


thanks



Russ

From: Eugene Zaikonnikov
Subject: Re: Newbie - Call assembly language function from Lisp?
Date: 
Message-ID: <941565771.137968@lxms.cit.org.by>
Russ Urquhart <······@aud.alcatel.com> wrote in message
······················@aud.alcatel.com...
> As the subject says. I'm getting into Lisp, but was wondering if there
> was a way to call assembly routines that i've written?
>
> Ideally this would be on an Intel machine, but not necessarily
> restricted to that architecture alone.
>
Obviously, there's no standard way to do this. I believe Corman Lisp (a Lisp
compiler for Windows) allows x86 assembly code insertion into lisp
functions, and since you work under NT, it may be acceptable.
Generally you can call your code using Foreign Function Interface, although
it is implementation-dependent too.

--
  Eugene.
From: Rainer Joswig
Subject: Re: Newbie - Call assembly language function from Lisp?
Date: 
Message-ID: <joswig-0211992109220001@194.163.195.67>
In article <················@lxms.cit.org.by>, "Eugene Zaikonnikov" <······@removeme.cit.org.by> wrote:

> Russ Urquhart <······@aud.alcatel.com> wrote in message
> ······················@aud.alcatel.com...
> > As the subject says. I'm getting into Lisp, but was wondering if there
> > was a way to call assembly routines that i've written?
> >
> > Ideally this would be on an Intel machine, but not necessarily
> > restricted to that architecture alone.
> >
> Obviously, there's no standard way to do this. I believe Corman Lisp (a Lisp
> compiler for Windows) allows x86 assembly code insertion into lisp
> functions,

Macintosh Common Lisp allows inline assembler and you can call
routines from shared libraries.
From: Christopher R. Barry
Subject: Re: Newbie - Call assembly language function from Lisp?
Date: 
Message-ID: <874sf4qcvx.fsf@2xtreme.net>
Russ Urquhart <······@aud.alcatel.com> writes:

> As the subject says. I'm getting into Lisp, but was wondering if there
> was a way to call assembly routines that i've written?
> 
> Ideally this would be on an Intel machine, but not necessarily
> restricted to that architecture alone.
> 
> Any help is greatly appreciated!

There are basically two ways you can go about doing this.

The first, most portable, and probably best way is to use a FFI
(Foreign Function Interface). Lisps like Allegro CL support loading of
foreign object code in C-compatible object formats; namely C and
Fortran object files. Additionally, most C compilers support inline
assembler procedures. You could define your assembler routines in .c
files and then compile them to .dll, .so, or whatever your operating
system's shared library format is, and then load them and set up the
bindings per your Lisp's documentation. Alternatively, you could
generate the .o files from assembler source files (.S or whatever)
instead of having your C compiler do it for you....

The second way would be to see if your Lisp supports and documents an
interface to a LAP (Lisp Assembler Program). MCL for the Mac does, for 
example.

Christopher
From: Friedrich Dominicus
Subject: Re: Newbie - Call assembly language function from Lisp?
Date: 
Message-ID: <381FE82A.ADDF1C54@inka.de>
Christopher R. Barry wrote:
> 
> Russ Urquhart <······@aud.alcatel.com> writes:
> 
> > As the subject says. I'm getting into Lisp, but was wondering if there
> > was a way to call assembly routines that i've written?
> >
> > Ideally this would be on an Intel machine, but not necessarily
> > restricted to that architecture alone.
> >
> > Any help is greatly appreciated!
> 
> There are basically two ways you can go about doing this.
> 
> The first, most portable, and probably best way is to use a FFI
> (Foreign Function Interface). Lisps like Allegro CL support loading of
> foreign object code in C-compatible object formats; namely C and
> Fortran object files. Additionally, most C compilers support inline
> assembler procedures. 


It isn't standard in C too. So you have to fiddle with Lisp->C which is
dependend on the FFI and you have to fiddle with C-> Assembler which is
again compiler dependend so I would not hamper with two different things
but try to use Assembler directly from Lisp at least I don't have to
bother about C than. 

Just my 2 cents
Friedrich
From: Christopher R. Barry
Subject: Re: Newbie - Call assembly language function from Lisp?
Date: 
Message-ID: <87r9i8ottm.fsf@2xtreme.net>
Friedrich Dominicus <···················@inka.de> writes:

> Christopher R. Barry wrote:
> > 
> > Russ Urquhart <······@aud.alcatel.com> writes:
> > 
> > > As the subject says. I'm getting into Lisp, but was wondering if there
> > > was a way to call assembly routines that i've written?
> > >
> > > Ideally this would be on an Intel machine, but not necessarily
> > > restricted to that architecture alone.
> > >
> > > Any help is greatly appreciated!
> > 
> > There are basically two ways you can go about doing this.
> > 
> > The first, most portable, and probably best way is to use a FFI
> > (Foreign Function Interface). Lisps like Allegro CL support loading of
> > foreign object code in C-compatible object formats; namely C and
> > Fortran object files. Additionally, most C compilers support inline
> > assembler procedures. 
> 
> 
> It isn't standard in C too. So you have to fiddle with Lisp->C which is
> dependend on the FFI and you have to fiddle with C-> Assembler which is
> again compiler dependend so I would not hamper with two different things
> but try to use Assembler directly from Lisp at least I don't have to
> bother about C than. 

And I mentioned this as a possible second option in the part of my
post which you elided. Now which Lisps actually document and support
using assembly language directly from Lisp? (I mentioned that MCL can
do this in the part you elided. Genera, of course, also lets you get
at the microcode. But what other Lisps?)

Christopher
From: Friedrich Dominicus
Subject: Re: Newbie - Call assembly language function from Lisp?
Date: 
Message-ID: <382132B2.BEA0DB80@inka.de>
> And I mentioned this as a possible second option in the part of my
> post which you elided. Now which Lisps actually document and support
> using assembly language directly from Lisp? (I mentioned that MCL can
> do this in the part you elided. Genera, of course, also lets you get
> at the microcode. But what other Lisps?)

You're right I have over-read it. Sorry for that

Regards
Friedrich
From: Roger Corman
Subject: Re: Newbie - Call assembly language function from Lisp?
Date: 
Message-ID: <3821deeb.153578474@nntp.best.com>
On Tue, 02 Nov 1999 11:41:35 -0600, Russ Urquhart
<······@aud.alcatel.com> wrote:

>As the subject says. I'm getting into Lisp, but was wondering if there
>was a way to call assembly routines that i've written?
>
>Ideally this would be on an Intel machine, but not necessarily
>restricted to that architecture alone.
>
>Any help is greatly appreciated!
>
>
>thanks
>
>
>
>Russ
Corman Lisp, on Windows platforms, provides a rich set ways to
incorporate assembly language into your code. They are used quite a
bit in the system souce code (included with the product) so yu can
find many examples. In short, you can:

- define a function (callable from lisp) entirely in x86 assembler
(using DEFASM)
- incorporate snippets of x86 assembler into any lambda definition
(using DEFUN for example)
- define code generators which extend the compiler by inserting x86
code that you specify when a specific form (of your choosing) is
compiled

Since all expressions and functions are always compiled, this scheme
works very well. There is also the ability to define assembly macros.
And all x86 code is written in standard MASM syntax (fairly close
anyway). Example:
;;;;
;;;;	Common Lisp IDENTITY function.
;;;;
(defasm identity (obj)
    {
        push	ebp
        mov	ebp, esp
        cmp 	ecx, 1
        je 		short :next
        callp 	_wrong-number-of-args-error	;; assembler macro
    :next
        mov 	eax, [ebp + ARGS_OFFSET]
        pop	ebp
        ret
    })

A big caveat:
Don't get into assembler unless you really need it and know what you
are doing. There are subtle interactions with the garbage collection
and threading model, and conventions you must adhere to, to do this
correctly.

Roger Corman