Newbie - Call assembly language function from Lisp?

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

Sat, 20 Apr 2002 03:00:00 GMT

Eugene Zaikonniko#2 / 8

Newbie - Call assembly language function from Lisp?

Quote:

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

Sat, 20 Apr 2002 03:00:00 GMT

Rainer Josw#3 / 8

Newbie - Call assembly language function from Lisp?

Quote:

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

Macintosh Common Lisp allows inline assembler and you can call routines from shared libraries.

Sat, 20 Apr 2002 03:00:00 GMT

Christopher R. Bar#4 / 8

Newbie - Call assembly language function from Lisp?

Quote:

> 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

Sun, 21 Apr 2002 03:00:00 GMT

Friedrich Dominicu#5 / 8

Newbie - Call assembly language function from Lisp?

Quote:

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

Sun, 21 Apr 2002 03:00:00 GMT

Christopher R. Bar#6 / 8

Newbie - Call assembly language function from Lisp?

Quote:

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

> 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

Sun, 21 Apr 2002 03:00:00 GMT

Friedrich Dominicu#7 / 8

Newbie - Call assembly language function from Lisp?

Quote:

> 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

Mon, 22 Apr 2002 03:00:00 GMT

Roger Corm#8 / 8

Newbie - Call assembly language function from Lisp?

On Tue, 02 Nov 1999 11:41:35 -0600, Russ Urquhart

Quote:

>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

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.