flat assembler
Message board for the users of flat assembler.

Index > Compiler Internals > Feature req: Export constants to file

Author
Thread Post new topic Reply to topic
TNick



Joined: 29 Jan 2008
Posts: 13
Location: Brasov, Romania
TNick 20 Jun 2008, 12:34
Hello!

First of all, if this thing was previously requested, I beg your pardon. I did not find anything like this while searching in forum.

The idea would be to be able to export some constants (or all) after the assembler has done it's passes. No doubt one can group constants in a include file that can later be used in some place else, but you may need to export the addresses of labels and the size of a pice of code.

There may be two approaches:
1) a special directive for this kind of file => 0, 1 or more text files may be generated
Code:

Lbl01:
; ...

Lbl01.size = $ - Lbl01

.ConstExp
{
    FILE = 'c:\test\test1.inc'

; some coment that will apear in generated file, too

    ExpC Lbl01
    ExpC Lbl01 as Label01

    ExpC Lbl01.size
}
    

This would generate a file (c:\test\test1.inc) with this content:

Code:
; some coment that will apear in generated file, too

    Lbl01 = 0x1000
    Label01 = 0x1000

    Lbl01.size = 0x124
    

(assuming that Lbl01 is placed at 0x1000 and there were 0x124 bytes until Lbl01.size) The format of output (0x or h, base for the number, = or equ) may also be controlled by options after FILE ...


2) a special macro, using same format as ExpC, but one that may be placed anywhere in the file. However, there would be only one file that will have all constants... or there may be optional arguments to this "macro"
to tell the file. If omitted, the constant may be added to default file.


What do you think?

Nick
Post 20 Jun 2008, 12:34
View user's profile Send private message Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP 21 Jun 2008, 15:00
It's an interesting idea, I'm not sure of many practical uses of it though. So your idea is to has certain constants be written to a file at compile time? It could possibly be used for assembling log files... Such as when you assemble any program with FASM, it would (opitionally) drop a file in the same dir that says things like '3 passes, xxx seconds, any bugs...' or whatever is usually outputted to the console.

I think it's a great idea now that I think of those uses, fairly simple to implement the non-macro side of it (stick a little routine in FASM source before assembling?). I do not wish to do this project myself, but it would be a very nice little addition for those who want it.

Example command-line?:

C:\> FASM.exe Program.asm Program.exe /l LogFile.txt

New command option, '/l' is followed by a file to output the buffers to instead of the console.
Post 21 Jun 2008, 15:00
View user's profile Send private message Visit poster's website Reply with quote
TNick



Joined: 29 Jan 2008
Posts: 13
Location: Brasov, Romania
TNick 21 Jun 2008, 16:01
Hello, Alex!

The practical use is, for example, that you may build individual pices of a ... well.. let's call it a distribution for OS. Long talk ... Or, when you define a set of constants (a structure) where each element's position and size may depend on size of previously defined elements in structure and on outside elements. I end up defining macros for this purpose. But you may want to export a clean set of constants like:
Code:
Str1.el1 = 0x1000
Str1.el2 = 0x1235
    

So, you see, I was thinking about a file that may be latter passes as include to the assembler.

However, since I was stuck, I start reading the FASM source code, found the SYMBDUMP here, read that, too (this was the great help), and now I am almost ready to post the way you can modify source code to export those constants. I just want to add support for conditional export.
Ready untill now:
- inserted "expform" keyword in FASM, to let you tell the format of the export (include file or source file for Labelmaster-Olly) and option to export all labels or just those that are marked. Something like this:
Code:
       ExpForm         olly,all,"Filename.someext"
       ExpForm         none
        ExpForm         incl,all
    ExpForm         incl,mark
   ExpForm         olly,mark    

Still, this is rudimentary, 'couse you can use this just once (infact, only the last one is used).
To mark which constant to export, you will have to insert a macro in your source code with onne argument: the label that you want to export. This will be added to a "pattern" string (something like E_X_P_L_B_L____). When is to export the label, if option is on, the pattern is searched in label name. It is only exported if the pattern is found (withoput the pattern, of course). <--I'm not really proud of this, but, until I will have a better understanding of FASM source code, this is all I could came up with...

But, as I said, in some hours I will post it all.

About your idea:
- I guess you know there is a snippet to generate a listing
- to store console output in a file.. that isn't that hard, either. There are 3 functions that display something, if I recall correctly. The problem, I think, is with memory that you have to get it in fixed size at program start. So, if the output is longer, you will simply lost it.

Nick
P.S.: Damn, it was easier to write the code than to explain it...
Post 21 Jun 2008, 16:01
View user's profile Send private message Reply with quote
AlexP



Joined: 14 Nov 2007
Posts: 561
Location: Out the window. Yes, that one.
AlexP 21 Jun 2008, 16:58
Wow, that's a very nice idea. It could really help with chained projects, but are there any things that could go wrong with it Confused. For example, you compile the main file of ... let's use your example, an OS. One file is compiled (the constants are written to another file), the next file is compiled automatically, and so on... But will the file be guaranteed to be written by the time the next file is pre-processed? You should make a few example files to demonstrate the rigidity of that idea.

It is a very nice idea Nick, and I hope it will work (maybe even get put into a future FASM release if it finds enough supporters). I guess it would work quite nice if you put your routine at the start of the pre-processor or something to ensure it will be there when the next file is grabbed. Good luck!
Post 21 Jun 2008, 16:58
View user's profile Send private message Visit poster's website Reply with quote
TNick



Joined: 29 Jan 2008
Posts: 13
Location: Brasov, Romania
TNick 22 Jun 2008, 06:48
Ok. Here it is. This may clarify all. Smile

There are many infos in the file, but here is a general layout:

First thing first: in order to build this feature in FASM, you have to INCLUDE this file in FASM.ASM. Second, you have to modify TABLES.INC by inserting:
Code:
 db 7,'expform'
 dw define_export-preprocessor    

in preprocessor_directives. Note that entries must be sorted.

A call ExportConst must be inserted in fasm.asm, just after the call assembler and before the call formatter

Now assemble new fasm for your os, and we're there.



USAGE:
Your old sources will be assembled without any diffrence. Nothing new will happen unless you insert a ExpForm directive. This may take up to 3 arguments:
- first one must be the format that you expect: olly format (olly) will place hex values in file, a tab and label's name; include format (incl) will generate a file that can be interpreted by fasm, having the label, spaces, a = and 0xhex value)
- second, you may tell if all labels should be exported (all) or only those that are marked (mark) - to see how to mark them, see below.
-third, the file path (optional) and name of output file. It would be a nice thing to enclose this in quotes.
You may place this directive anywhere you want. Note that it will follow same rules as "macro" or "struct".
Here are some examples of use:
Code:
        ExpForm         olly,all
    ExpForm         olly,mark
   ExpForm         olly,all,"L_A_B_E_L_S.inc"
        ExpForm         none
        ExpForm         incl
        ExpForm         incl,mark
   ExpForm         incl,all
    ExpForm         incl,mark,"L_A_B_E_L_S.inc"
    


If an invalid string is placed at one argument's position, a warning will be shown and there will be no output.
If multiple ExpForm are found while preprocessing, only the last one will be used to format the output.

To mark a symbol for export (so that it will be exported when you use (mark) in second argument for ExpForm), this string
Quote:
E_X_P_O_R_T__1234567____________
must be added to symbol's name. To ease this, you may use this simple macro:

Code:
macro           ExportConst     Constname*
 {
       E_X_P_O_R_T__1234567____________ # Constname = Constname
 }
    


and, then:
Code:
myVar01  =  10

...

ExportConst  myVar01
    


I will value your input and test results. Let me know if there are any problems with this.

Nick


Description: Modifier for FASM core, in order to generate Labelmaster compatible or include file from processed source.
Download
Filename: LblExport.asm
Filesize: 11.94 KB
Downloaded: 361 Time(s)

Post 22 Jun 2008, 06:48
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.