flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > File access in macro

Author
Thread Post new topic Reply to topic
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 23 Jan 2010, 06:10
Hi guys,

I was wondering if I could create a macro which can write to an external file in preprocesor time. The idea is something like the following:

Code:
AddToList    Function1, ID_Function1, 1    


So, that macro will write into an external file (let's call it "const.inc") the information:

Code:
ID_Function1 = 1    


So, from the macro I can first write/append to the external file and also do some other functionality.

Thanks!!!
Post 23 Jan 2010, 06:10
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 23 Jan 2010, 06:54
The short answer is that it is impossible to write to a file other than the output file.

But do you really want this? What would be the problem if those constants are generated every time?
Post 23 Jan 2010, 06:54
View user's profile Send private message Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 23 Jan 2010, 08:47
Hello LocoDelAssembly,

Thanks for the fast reply.

Well, the constants file will be generated when the .asm file is modified (makefile rules)

The idea is that at the moment, when I add a new element I have to go to the constant file (.inc) and add an entry to it. After that, I go to another file (.asm) and associate the constant with the function name. So, it's like making double work and with the chances of introducing human typying errors Smile

I know that it might sound a bit stupid the above and you might think of other simpler solutions, but it has to be like that Smile

Well, my question should have been more general and it would have been:

"Can I call an external application from FASM preprocesor?" So, that external application could do all that work to append to file or whatever we want.

Well, maybe it's a good feature to add to FASM the support to call an external application from its preprocesor Smile

Thanks!!!
Post 23 Jan 2010, 08:47
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 23 Jan 2010, 09:06
You could use display to output information to the console. You still have to strip the first and last lines (the fasm greeting and the assembly statistics).
Code:
macro AddToList name,value {
  display `name," = ",`value,13,10
}    
Post 23 Jan 2010, 09:06
View user's profile Send private message Visit poster's website Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 23 Jan 2010, 18:18
Ah I understand now, you want to make an object/dll library and have the "inc" for other programs to use?

Well, this might work:
Code:
format binary as '.inc'

LIST equ
macro AddToList name, value
{
   LIST equ LIST `name = `value,
}

; You'll need to overload some directives to make virtual work properly like "section", "segment", "format", etc.
virtual
   include 'real_source.asm'
end virtual

match list, LIST
{
   irp val, list
   \{
      match a==b, val
      \\{
         db \\`a, " = ", \\`b, 10
      \\}
   \}
}    
I hope there are no side-effects that I'm overlooking.

[edit]Well, it won't work with calculated constants, the new REPT feature introduced in FASM 1.69 might help a bit, but yet it won't be complete enough (things like "$-someLabel" won't be resolved)[/edit]
Post 23 Jan 2010, 18:18
View user's profile Send private message Reply with quote
alorent



Joined: 05 Dec 2005
Posts: 221
alorent 23 Jan 2010, 21:51
Thanks revolution and LocoDelAssembly!!! I think that I need some time to digest your solutions Smile

Thanks a lot!!!
Post 23 Jan 2010, 21:51
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.