cFASM (calling FASM as a C function)
- From: "rhyde@xxxxxxxxxx" <rhyde@xxxxxxxxxx>
- Date: 17 Mar 2007 20:10:29 -0700
Hi All,
I've been working on converting FASM into a statically-linkable
library module that can be called from C (or just about any other
language that allows you to statically link in an object module).
Over the past couple of hours I've gotten this working to the point
that a C program can call this module to recompile the original FASM
source code, obtaining the exact object code that FASM.EXE produces
when processing the file.
This, of course, is no indication that all the problems have been
eradicated, but it's far enough along that I feel comfortable sharing
the code with anyone who is interested in playing around with it.
The files can be found on Webster at this URL:
http://webster.cs.ucr.edu/cfasm.zip
The zip file contains (approximately) the following files:
cfasm.c - A sample C program that calls FASM and provides library
support for cFASM.
FASM.ASM - The original source file I used to create the hFASM.hla
source file. This is the FASM source code with all the include files
inserted into the main program (this was useful during the conversion
process when I was running FASM through several perl scripts to
convert the code to HLA syntax).
FLICENSE.TXT - The FASM license. It applies to cFASM and hFASM.
hfasm.hla, hfasm.hhf - The HLA source files. I converted FASM.ASM to
HLA syntax (as I prefer supporting this code under HLA rather than
FASM -- and ultimately this code is for *my* project, not your's, so
your preferences don't matter here).
makefile - a makefile to build the cFASM object module or the
standalone hFASM version.
In hFASM, I've dropped all the existing FASM interface code and
replaced it with calls to the HLA stdlib. Therefore, this code
*should* port to Linux without any effort. I have not tried this,
however, and I wouldn't be surprised to find a few gotchas here and
there.
The cFASM.c code was written for Borland C++ 5.0 and I don't believe
that porting it to GCC (or some other C compiler) will be much work,
but I'd be surprised to find that it compiles and runs without any
changes whatsoever at all.
The external linkages assume that external names have a "_" prepended
to them when written in assembly. If your C compiler doesn't support
this, then you'll have to manually prepend "_" to the function names
in the C source file (or remove them from the external declarations in
the HLA source file).
I have refactored the FASM source code quite a bit. It still needs a
*lot* more refactoring and optimization, but that will come with
time. I've added comments to about 20% of the code. Warning: some of
the comments are wrong -- you learn how things *really* work as you
spend more time with the code. Again, this is something I'll get
around to fixing in the future.
I've modified the symbol table lookup routines. Sped them up a bit and
used a hash table rather than the hash tree scheme previously used.
This saves a bit of memory for large projects (e.g., assembling the
FASM.ASM source code). There are *lots* of opportunities to speed up
the code, but it really needs to be refactored first.
Enjoy!
Cheers,
Randy Hyde
.
- Follow-Ups:
- Re: cFASM (calling FASM as a C function)
- From: vid512@xxxxxxxxx
- Re: cFASM (calling FASM as a C function)
- From: vid512@xxxxxxxxx
- Re: cFASM (calling FASM as a C function)
- From: Phil Carmody
- Re: cFASM (calling FASM as a C function)
- From: Betov
- Re: cFASM (calling FASM as a C function)
- Prev by Date: Re: my assembler is better than your assembler
- Next by Date: Re: Ten years later
- Previous by thread: optimizing size or speed
- Next by thread: Re: cFASM (calling FASM as a C function)
- Index(es):
Relevant Pages
|