cFASM (calling FASM as a C function)



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

.



Relevant Pages

  • Re: Help me about this question.
    ... As HLA really requires nothing more from FASM, ... I'll have to set up a Linux box to test this one of these days. ... Is it a "benefit" to be able to view code that won't assemble? ...
    (alt.lang.asm)
  • Re: Help me about this question.
    ... If you don't think that the FASM ... better source code formatting, then that explains why your source code ... complaining about the quality of the HLA standard library code? ... to compile its own Win32 Equates list, clown. ...
    (alt.lang.asm)
  • Re: HLA v1.90 is now available on Webster
    ... FASM is a good Assembler written by a guy called Thomasz Gritszar. ... FASM's code easier to read than the RosAsm source code, ... HLA is an absurd HLL Pre-Parser ...
    (alt.lang.asm)
  • Re: Help me about this question.
    ... No doubt you *can't*, clown. ... FASM application. ... complaining about the quality of the HLA standard library code? ... niche for people who want an assembler syntax that is similar to NASM ...
    (alt.lang.asm)
  • Re: Help me about this question.
    ... files that HLA produces in order to examine the operation of the ... It's a combination of Fasm code and Gas code. ... That will work on both Linux ... After all, you're emitting the code, it would only take a little cleanup to make it assemble... ...
    (alt.lang.asm)