flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > virtual: include data in output?

Author
Thread Post new topic Reply to topic
yoshimitsu



Joined: 07 Jul 2011
Posts: 96
yoshimitsu 17 Feb 2012, 04:24
Hi again,
I wanted to write a macro which parses a relatively big file, takes data out of it and writes it into the output file.
The file, which contains an offset to a string array, the amount of strings and another offset to an array with properties regarding the strings, should be loaded via virtual and then its strings should be extracted to write them into the actual output file.

Something like this:
Code:
macro x
{
  virtual
    file 'x.bin'
    load len dword from $
    load off1 dword from $+4
    load off2 dword from $+8
    repeat len
      load xyz from off1+%
      load abc from off2+%
      load def from off2+%+4
      ;do other stuff and then also write stuff into exe
    end repeat
  end virtual
}    


So is there any way to write data which doesn't get dropped in a virtual-directive?

The file is like 5mb and having the virtual inside a loop to load and calculate the offsets over and over again doesn't sound very convincing:

Code:
macro x
{
  while running
    virtual
      ;calculate offset of next element and stuff every iteration
      load data from xxx
    end virtual
    db data
  end while

}    
Post 17 Feb 2012, 04:24
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20333
Location: In your JS exploiting you and your system
revolution 17 Feb 2012, 04:33
yoshimitsu wrote:
So is there any way to write data which doesn't get dropped in a virtual-directive?
You can load up variables with data and place them back later:
Code:
virtual
  file ...
  load var1 dword ...
  load var2 dword ...
end virtual
  dd var1,var2    
Indeed that is really the purpose of virtual, to assign values to labels. You seem to want to use it for file processing, which is not really the intended purpose. Perhaps you should consider writing an external program to parse your data file?
Post 17 Feb 2012, 04:33
View user's profile Send private message Visit poster's website Reply with quote
yoshimitsu



Joined: 07 Jul 2011
Posts: 96
yoshimitsu 17 Feb 2012, 04:45
That's what the task is like :P
I'm trying to write an external program as a FASM macro.

Thing is I want to process a string array, not a fixed number of values.
So I would need to work with an indeterminate amount of labels and I can't really think of a way getting this to work.

I thought of something like an equ-array like the append-macro from the documentation, but that would mix assembler and preprocessor stage, wouldn't it?
Post 17 Feb 2012, 04:45
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20333
Location: In your JS exploiting you and your system
revolution 17 Feb 2012, 04:57
For an array of EQUs you would need to know ahead of time (before the file directive is executed) how many labels to allocate. Assembler always runs after the preprocessor so you can't back-port the label count into the preprocessor. The only possible way is to allocate the expected maximum number of labels and monitor inside the loop if you ever exceed this value. Not a nice solution no matter how you do it, but it could work.
Post 17 Feb 2012, 04:57
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.