flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Iterating through string / virtual & load performance

Author
Thread Post new topic Reply to topic
yoshimitsu



Joined: 07 Jul 2011
Posts: 96
yoshimitsu
Hey,
I'm wondering about the performance of this macro:
Code:
macro swap _str
{
  local c,size

  virtual at 0
   db _str
   size = $-$$
  end virtual

  repeat size
    virtual at 0
     db _str
     load c from %-1
    end virtual
    if c='a'
     db 'b'
     display 'b'
    else if c='b'
     db 'a'
     display 'a'
    else
     db c
     display c
    end if
  end repeat
}
swap 'ababababababccccccababababab'    

I actually want to make the macro partly define random values.
Its argument should contain an ascii pattern (for better readability and maintainability) which gets processed character by character and if a specific character is hit, the macro should insert a random byte instead (got no idea yet of how to define a random byte, still need to search the forum).

And since there is no irpc-directive and I additionally need to define bytes (means the main-loop cannot be inside of the virtual-directive as it would eat up the db's), the only solution I came up with was to use virtual in a loop.
But I mean switching to a temporary context via virtual plus saving the string, both over and over again, can't be that performant, can it?
Post 15 Feb 2012, 04:46
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16951
Location: In your JS exploiting you and your system
revolution
I don't know of any other way than the virtual thing. However, somehow, I expect this might apply under the "premature optimisation" category. Get it working first, then get it fast, right? If, after it is working, it is too slow then consider writing an exe file to do it instead (I don't know your exact context so I'm not sure if this is possible for you).

As for random values: That it is not possible. AFAIK the best you could achieve is pseudo-random with the timestamp (%t) as a seed.
Post 15 Feb 2012, 06:02
View user's profile Send private message Visit poster's website Reply with quote
yoshimitsu



Joined: 07 Jul 2011
Posts: 96
yoshimitsu
That's the problem :P
Because if I do it this way I don't think there will be much room for optimizations. Therefore I asked before writing the full macro, because I figured I might need to fully recode it elsewise.

It should just be a small macro at assembly stage to write the byte-arrays I need in a more comfortable way.
Take the string, replace every for example b-letters with a random number between 1 and 5 and save the other ones normally.

With randoms I actually meant using the timestamp-directive, but I still need to see how I actually should handle it to get it as close as to a trivial rand-function
Post 15 Feb 2012, 06:36
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16951
Location: In your JS exploiting you and your system
revolution
A simple PRNG like an LCG would be simple to implement.
Post 15 Feb 2012, 07:01
View user's profile Send private message Visit poster's website Reply with quote
yoshimitsu



Joined: 07 Jul 2011
Posts: 96
yoshimitsu
Already saw some posts regarding that, thanks.

So should I just use that virtual | db string | end virtual in a loop or is there any other, maybe better way of checking every single character of a string and saving it afterwards?
Post 15 Feb 2012, 07:16
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 16951
Location: In your JS exploiting you and your system
revolution
It occurs to me that you could do in place replacement:
Code:
s: db _str
repeat $-s
  load byte x from s+%-1
  <manipulate>
  store x byte at s+%-1
end repeat    
Post 15 Feb 2012, 09:48
View user's profile Send private message Visit poster's website Reply with quote
yoshimitsu



Joined: 07 Jul 2011
Posts: 96
yoshimitsu
I believe you're right, that should do the trick.
Thank you :)
Post 15 Feb 2012, 10:22
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.

Powered by rwasa.