Calling ML from C
4 messages in this thread
Can anyone tell me if any of the C class transcripts deal with calling
machine language routines from C? Or any good books? I've got the Abacus
book, but it doesn't show how to handle arguments passed from C. Any help
would be appreciated.
Jon Bojicic 71460,2023
It's not that hard to interface C and assembler, the arguments are on the
stack or in registers, depending on what kinds of routines you're calling,
and what you might have set up in options on your code and compiler. Which
compiler are you using? One, if your compiler came with any sample code,
there might be an example or two there; or if it came with the source code
to the library, you'll have many examples of C/asm connections. Or, if your
compiler can output assembly language output, then you can look at the
source code it generates.
John, thanks for responding. I'm using Lattice 5., and I have been looking
at the assembler code using OMD. What's confusing is that not all
subroutines use the LINK and UNLINK INSTRUCTIONS, for example. BTW, i am a
beginner at assembler. I've been looking for tutorials, and have the
Abacus books C for Advanced programmers, and "Amiga Machine Language", but
they are of limited help. (or maybe I'm of limited intelligence!). Do you
know if any of the stuff in the C classes deal with this? Jon Bojicic
71460,2023
Yes, under Lattice, you can optimize functions to keep things in registers
between calls which leads to the link-less subroutines you saw… in the
past, it was more common to see all subroutine calls begin and end with
link and unlink. Haven't you tried reading the Lattice manual about this?
The sections that describe the related areas of this (pragmas, command line
switches, etc.) describe what happens in terms of the generated code.