flat assembler
Message board for the users of flat assembler.

Index > Main > Fasm JIT Compilation

Author
Thread Post new topic Reply to topic
MattBro



Joined: 08 Nov 2003
Posts: 37
MattBro 26 Nov 2004, 05:17
I've been experimenting with compiler design in fasm for a while now. I've come to the point where I am considering some kind of JIT (just in time) compilation mode as a kind of interpreter for my toy language. Thus what I want to do is generate assembler code and compile it to machine code in memory and then execute it.

This means of course I have to supply all external references at run-time, but this information would be available to the interpreter. It would be nice if I could use fasm to do this rather than re-invent the wheel so to speak. The most 'straightforward' way would be to generate a text file containing fasm code that implements a DLL containing the code that was sent to the interpreter, followed by a fasm compile, and then a load of the DLL. I suspect this is not an overly efficient technique, especially since it involves hard-drive I/O, though perhaps, in the time scale of user interaction, it would be sufficient for small programs.

The other possibility would be to modify the fasm source to help me in my task. I do not know how difficult this would be, so I am asking the fasm community if they have any comments or suggestions.

Regards,
Matthew

_________________
-- -------------------------------------------------------
"I am the Way and the Truth and the Light, no one comes to the Father except through me" - Jesus
---------------------------------------------------------
Post 26 Nov 2004, 05:17
View user's profile Send private message Visit poster's website Reply with quote
crc



Joined: 21 Jun 2003
Posts: 637
Location: Penndel, PA [USA]
crc 26 Nov 2004, 10:38
I'd tend to think that it would be better to have a DLL containing FASM. You'd build the source for FASM to assemble in memory, pass the address of that buffer, and then load the resulting code in whatever way seems best (as a DLL, exe, or from another memory buffer). That should be faster than creating a .txt on disk and encountering the load times of FASM whenever you wanted to jit compile something.
Post 26 Nov 2004, 10:38
View user's profile Send private message Visit poster's website Reply with quote
MattBro



Joined: 08 Nov 2003
Posts: 37
MattBro 26 Nov 2004, 18:39
That's not a bad idea. Your suggestion would require a modification to the fasm compiler to run as a called subroutine I think. However, one thought along these lines, would be to create a disk partition in memory and use the fasm compiler as is, reading and writing files to the memory mapped partition.


I also seem to recall another thread somewhere that discussed the idea of running the compiler as a subroutine. I'll have to dig up that link to see if anyone has done anything in this area.
Post 26 Nov 2004, 18:39
View user's profile Send private message Visit poster's website Reply with quote
fasm9



Joined: 19 Jun 2003
Posts: 439
fasm9 26 Nov 2004, 20:14
similar project is there, though, dunno if it works for FASM.
you have to have familiar with c++.


gnu lightning 1.2 (2004-11-25)
http://www.gnu.org/software/lightning/lightning.html

--
Post 26 Nov 2004, 20:14
View user's profile Send private message Reply with quote
MattBro



Joined: 08 Nov 2003
Posts: 37
MattBro 26 Nov 2004, 22:03
Thanks for the post fasm9; its an interesting project. I would love to use it, however the license is a bit restrictive. I want to release my project under a license that allows commercial use.

I am also looking at this little project
http://mitglied.lycos.de/cschueler/asm/download.html
Post 26 Nov 2004, 22:03
View user's profile Send private message Visit poster's website Reply with quote
Octavio



Joined: 21 Jun 2003
Posts: 366
Location: Spain
Octavio 26 Nov 2004, 22:15
MattBro wrote:
That's not a bad idea. Your suggestion would require a modification to the fasm compiler to run as a called subroutine I think. However, one thought along these lines, would be to create a disk partition in memory and use the fasm compiler as is, reading and writing files to the memory mapped partition.


I also seem to recall another thread somewhere that discussed the idea of running the compiler as a subroutine. I'll have to dig up that link to see if anyone has done anything in this area.

You don´t need a ram disk, just modify fasm read and write routines to read from the memory area where the source is and write to a memory area to execute the program, the program should be in plain binary format to be ready to execute and call directly the code of the interpreter, not the OS,else you have to write some executable loader-linker.
I wrote a assembler called 'octasm' for dos, and this assembler can be used as a interpreter, and i think that there are some others too.
many assemblers are listed here: http://www.retroforth.org/asmchart/
Post 26 Nov 2004, 22:15
View user's profile Send private message Visit poster's website Reply with quote
MattBro



Joined: 08 Nov 2003
Posts: 37
MattBro 26 Nov 2004, 23:55
Quote:
You don´t need a ram disk, just modify fasm read and write routines to read from the memory area where the source is and write to a memory area to execute the program, the program should be in plain binary format to be ready to execute and call directly the code of the interpreter, not the OS,else you have to write some executable loader-linker.


Is it really that simple Octavio? I imagine that fasm must write some kind of header to it's .exe and .dll output files to make the code relocatable and loadable by the operating system. Your proposal requires that this header be bypassed I believe. Although external references can be supplied at compile time, there is also the issue of internal references, which, in some cases, can only be resolved after multiple passes. Moreover fasm will resolve internal refernces in such a way so as to make the code loadable by the operating system. I guess the point here is that fasm doesn't generate raw executable code; (unless it has features I don't know about) it generates operating system relocatable code, with all it's required headers and conventions.

The end result of this path is the need to have a routine that can load .exe or .dll formatted binaries already in memory into my interpreter. That's basically an OS operation. To make fasm generate code that can be executed without operating system intervention sounds like a more involved operation that simply changing the read and write subroutines, unless I am somehow missing your point.

_________________
-- -------------------------------------------------------
"I am the Way and the Truth and the Light, no one comes to the Father except through me" - Jesus
---------------------------------------------------------
Post 26 Nov 2004, 23:55
View user's profile Send private message Visit poster's website Reply with quote
Octavio



Joined: 21 Jun 2003
Posts: 366
Location: Spain
Octavio 27 Nov 2004, 12:04
yes, fasm can generate raw code and data read a bit more about it.
Post 27 Nov 2004, 12:04
View user's profile Send private message Visit poster's website Reply with quote
MattBro



Joined: 08 Nov 2003
Posts: 37
MattBro 27 Nov 2004, 18:28
OK yes, thanks Octavio, you are right. I just noticed the format binary directive. That makes your suggestion a possibility. I'll have to play around with it to see how it works.

Apparently you can also set the address at which the code will appear in memory using the org directive. Thats very cool and should hopefully resolve the issue about how internal labels are handled,.
Post 27 Nov 2004, 18:28
View user's profile Send private message Visit poster's website Reply with quote
penang



Joined: 01 Oct 2004
Posts: 59
penang 28 Nov 2004, 14:31
[quote="MattBro"]

Thanks for the post fasm9; its an interesting project. I would love to use it, however the license is a bit restrictive. I want to release my project under a license that allows commercial use.

[/quote]

I don't think the license bans you from using it commercially. All it says is whatever changes you do to the original code, you contribute it back to the project.
Post 28 Nov 2004, 14:31
View user's profile Send private message Reply with quote
MattBro



Joined: 08 Nov 2003
Posts: 37
MattBro 28 Nov 2004, 19:00
Alas, the problem for most commercial use of such a library is clause 6 of the GNU lesser public license. As I read it, it requires that all source be distributed with any programs that link to the library. Now I actually intend to distribute my source freely once it's mature enough, however if I used lightning, other users of my code (if there are any) would be constrained by this license, likely making it a non-starter for most types of commercial distribution.


Many 'free' compilers such as OCAML for example, distribute their software with the same license, but with a clause 6 exemption. I am enclosing the license so you can see it for yourself. This is the license file I downloaded from the lightning package.


Description: GLPL enclosed
Download
Filename: COPYING_LESSER.txt
Filesize: 25.8 KB
Downloaded: 506 Time(s)

Post 28 Nov 2004, 19:00
View user's profile Send private message Visit poster's website Reply with quote
fasm9



Joined: 19 Jun 2003
Posts: 439
fasm9 02 Dec 2004, 21:43
try to contact the author, or gnu ppl. all we need is talk, meeting, conversation.

i think "commercial use" is one thing, "open source" is another thing. so open source with commercial use is possible, imho.

--
of course, this is my view of GLGPL.
Post 02 Dec 2004, 21:43
View user's profile Send private message Reply with quote
trullyblessed



Joined: 13 Feb 2005
Posts: 2
Location: USA
trullyblessed 13 Feb 2005, 22:50
For Octavio
"I wrote a assembler called 'octasm' for dos, and this assembler can be used as a interpreter,"


We have this assembler.
We are using it on an in house project and would like to know if there is any thing else available on it?
Royce

_________________
royce
Post 13 Feb 2005, 22:50
View user's profile Send private message Visit poster's website Reply with quote
Octavio



Joined: 21 Jun 2003
Posts: 366
Location: Spain
Octavio 14 Feb 2005, 02:51
trullyblessed wrote:
For Octavio
"I wrote a assembler called 'octasm' for dos, and this assembler can be used as a interpreter,"


We have this assembler.
We are using it on an in house project and would like to know if there is any thing else available on it?
Royce

You are the first octasm user i have notice Very Happy
so don´t expect to find very much.
i have a os writen in octasm on my web page, it has about 400kb of source code. the octasm version that comes with my os is more updated
than the old dos version ,but only works on my os.
Post 14 Feb 2005, 02:51
View user's profile Send private message Visit poster's website Reply with quote
trullyblessed



Joined: 13 Feb 2005
Posts: 2
Location: USA
trullyblessed 14 Feb 2005, 04:41
You are the first octasm user i have notice
so don´t expect to find very much.
i have a os writen in octasm on my web page, it has about 400kb of source code. the octasm version that comes with my os is more updated
than the old dos version ,but only works on my os.[

We like it for many reasons.
We e-mailed you after we left our post, didn't expect a reply here so soon.
Why does it only work with your O/S?
[/quote]

_________________
royce
Post 14 Feb 2005, 04:41
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.