flat assembler
Message board for the users of flat assembler.

Index > Main > Compiler using FASM

Author
Thread Post new topic Reply to topic
Azh321



Joined: 27 Jan 2005
Posts: 12
Azh321
Im writing a compiler, its in C, and it generates an asm file. My friend made one also, and it used NASM to assemble the asm file. I looked at the outputted asm code and its so simple, he just uses C functions.... "extern printf" and such so he can use any functions. Though, I have no experience with NASM and would rather use FASM for mine, but is there a similar way to do that? (note: im not a pro at asm, I have bare minimum knowledge of using it)

And if you guys are curious about the language, it is pretty similar to Forth. Here is a program that defines a function, aka "word", that outputs hello world and then calls that function.

Code:
 :define HelloWorld
    Push "Hello, World!"
    Out
 :end

  HelloWorld
     


Last edited by Azh321 on 21 Feb 2005, 00:48; edited 2 times in total
Post 20 Feb 2005, 21:17
View user's profile Send private message AIM Address Reply with quote
denial



Joined: 12 Sep 2004
Posts: 98
denial
I'm a newbie too, but I hope I can help you:

If you wanna write a compiler, it should also be fast. I think using external C functions will make your language pretty slow. So maybe you should write your functions in assembler. However, I think it's possible to use extern C functions. You can either write an own DLL in C and import it at runtime with the library/import-macros, or you can use the C-libary provided by windows. I read about somewhere.
Post 20 Feb 2005, 22:32
View user's profile Send private message Reply with quote
Azh321



Joined: 27 Jan 2005
Posts: 12
Azh321
Actually it doesnt matter if its fast. With todays cpu speeds and such, plus this is a simple language. And im a not a "newbie" or else I wouldnt be programming a compiler. I have decided what I will be doing for the generated asm though.
I will program each of the built-in functions in asm and it will include that at the bottom of the asm source and call that when needed.
Post 21 Feb 2005, 00:01
View user's profile Send private message AIM Address Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
well, azh. I see it that way: if you see that compiler is problem that you cannot solve by your own,m than it is too hard taks for you FOR NOW (it will change in soon future if you keep it up with asm). Try to make some text-file parser or simple ineterpreter, i believe you will son see what i was talking about. Just keep your compiler project for yourself until you can make it, and try some similar but simpler tasks before. The general rule is: trust yourself. I've done it this way and i think i 've made it far enough without embarassing myself.
Post 21 Feb 2005, 00:31
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Azh321



Joined: 27 Jan 2005
Posts: 12
Azh321
Where do you guys get the part of me being a noob? I have made interpreters, I have made VM's. I have even worked on a few cpu emulators. Why would I ever want to make a simple one when I have made complex ones already? I CAN make this, all I was asking was if there was something similar to NASM's extern keyword.
Post 21 Feb 2005, 00:46
View user's profile Send private message AIM Address Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
sorry then, there's too many newbies asking now so i was fooled by the fact. But nayway, there is keyword "extrn", just look at http://flatassembler.net/docs.php?article=manual#2.4.3. you know, RTFM.

I hope that's what you was asking for.
Post 21 Feb 2005, 00:56
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Azh321



Joined: 27 Jan 2005
Posts: 12
Azh321
Yes, I saw that. But thanks for helping.
Post 21 Feb 2005, 01:06
View user's profile Send private message AIM Address Reply with quote
calm_observer



Joined: 08 Jan 2005
Posts: 17
Location: New Nexico, USA
calm_observer
Azh321 wrote:
Im writing a compiler, its in C, and it generates an asm file...he just uses C functions.... "extern printf" and such so he can use any functions...is there a similar way to do that?

I am for certain not a fasm expert, but I think what you are looking for comes under the assembler directives 'import', 'export' and 'extrn', look under section '2.4 Formatter Directives' and varies depending upon the output format. You can find an example for both Portable Executable in PEDEMO.ASM and mscoff in MSCOFF.ASM in the examples that come with the assembler. Also you need to look at the various forms of the 'invoke' macros.

As someone new to fasm you will find (I am finding) that you'll need to put in some work when it comes to understanding macros, this was also true when I used nasm. Check the macro section on this forum for more help than I can possibly give you.

Now to your compiler. You may want to check out this site http://www-personal.umich.edu/~williams/archive/forth/hatforth/hatforth.html

"^Forth (pronounced "hat Forth", or "to the power Forth") is a dialect of Forth intended for automatic text translation into source for the implementation language of a normal Forth. It grew out of a set of assembly language macros dating back to mid-1991, written for the Ann Arbor macro assembler (AAma by Martinus Veltman) to run on Motorola 680x0 cpu's under a variety of operating systems."

Finally, keep us posted as to your progress Cool

_________________
EDUCATION, n.
That which discloses to the wise and disguises from the foolish their lack of understanding.
Post 21 Feb 2005, 21:30
View user's profile Send private message 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.