Newbie - Call assembly language function from Lisp? 
Author Message
 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  
 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  
 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,

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


Sat, 20 Apr 2002 03:00:00 GMT  
 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  
 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  
 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.

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

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



Mon, 22 Apr 2002 03:00:00 GMT  
 
 [ 8 post ] 

 Relevant Pages 

1. High Level Language with Easy Calls to Assembly Language

2. Assembly Language for TI-86 or the Z80 assembly Language

3. VC++ calling fortran function and fortran function calling a c++ function

4. Newbie: Needs assembly language FAQs...Help Appreciated!

5. Please help an assembly language newbie!

6. Help needed: Use the EXEC function in assembly language

7. looking for assembly language nat. logarithm function

8. Exec function in assembly language

9. Creating a SURD function in assembly language

10. Math functions in Assembly language.

11. Calling an Assembly language routine from REXX

12. Calling C functions from Assembly

 

 
Powered by phpBB® Forum Software