flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Stuck with sorting macros |
Author |
|
revolution 30 Mar 2009, 06:10
I think the first to realise with fasm is the separation of the preprocessor-stage and the assembler-stage. Above you have mixed up the two parts so that makes the macros impossible to work like that.
You need to decide beforehand if you want to use the preprocessor-stage for sorting (hard) or the assembler-stage for sorting (easier). One place to start looking for examples is the export macros in the windows package. It is an assembler-stage based sorter but does not sort strings of unequal length, it sorts the indices only. So you will need to make a few changes to get it to work with variable length strings. |
|||
30 Mar 2009, 06:10 |
|
Grom PE 30 Mar 2009, 06:37
Thanks, revolution, but I don't really see where sorting occurs in export macros. What does it sort exactly?
I have fasm 1.67.27 if it does matter. |
|||
30 Mar 2009, 06:37 |
|
revolution 30 Mar 2009, 06:53
This part:
Code: common local x,y,z,str1,str2,v1,v2 x = count shr 1 while x > 0 y = x while y < count z = y while z-x >= 0 load v1 dword from names+z*4 str1=($-RVA $)+v1 load v2 dword from names+(z-x)*4 str2=($-RVA $)+v2 while v1 > 0 load v1 from str1+%-1 load v2 from str2+%-1 if v1 <> v2 break end if end while if v1<v2 load v1 dword from names+z*4 load v2 dword from names+(z-x)*4 store dword v1 at names+(z-x)*4 store dword v2 at names+z*4 load v1 word from ordinal+z*2 load v2 word from ordinal+(z-x)*2 store word v1 at ordinal+(z-x)*2 store word v2 at ordinal+z*2 else break end if z = z-x end while y = y+1 end while x = x shr 1 end while } |
|||
30 Mar 2009, 06:53 |
|
Grom PE 30 Mar 2009, 07:31
Ah! Now I see.
Now I'm trying to understand how can I use it. Imagine we have a string sorting macro, how does it help? I guess we need a list sorting macro... |
|||
30 Mar 2009, 07:31 |
|
revolution 30 Mar 2009, 16:42
Here is a very simple preprocessor sorter, but it still requires a manually set maximum loop counter (256 in this case):
Code: macro sortme level*,text* { @sort#level equ text @sort#level#flag equ y } macro dosort { rept 256 level:0 \{ match =y,@sort\#level\#flag \\{ db @sort\#level \\} \} } sortme 3,'should ' sortme 255,'in between!' sortme 1,'These ' sortme 200,'sort everything ' sortme 2,'macros ' dosort |
|||
30 Mar 2009, 16:42 |
|
Grom PE 30 Mar 2009, 18:21
Thank you, revolution!
I actually wanted to remove a limitation in my patching macros that "patchat" offsets must be in ascending order, but trying several times with integrating your sorter, I was able only to complicate the syntax (i.e. couldn't just remove the limitation without changing the syntax), so I guess I'll just leave these macros as is, until — I get more experienced with fasm, — or somebody suggests a clear syntax solution, — or Tomasz makes something interesting that allows changing assembling point =) |
|||
30 Mar 2009, 18:21 |
|
Madis731 31 Mar 2009, 10:31
Is this more ... logical?
Code: macro sortme order*,text* { sort#order equ text } macro dosort { rept 256 order:0 \{ if defined sort\#order db sort\#order end if \} } sortme 3,'should ' sortme 255,'in between!' sortme 1,'These ' sortme 200,'sort everything ' sortme 2,'macros ' dosort |
|||
31 Mar 2009, 10:31 |
|
revolution 31 Mar 2009, 11:07
Uses the assembler-stage. My posting was preprocessor-stage only.
|
|||
31 Mar 2009, 11:07 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.