flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Building lists efficiently in fasm |
Author |
|
Tomasz Grysztar 04 Oct 2010, 07:58
You can decrease the memory usage further by reducing the number of empty lines generated:
Code: macro list_builder name { local m,c c equ 0 macro .#name [a] \{ \common rept 1 x:c+1 \\{ c equ x macro m\\#x a \\} \} macro name#_list \{ rept c x \\{ m\\#x \\} \} } list_builder list2 And some other interesting version would be to use the numbered lists: Code: c equ 0 macro .listx id,[a] { common rept 1 x:c+1,y:id*1000000+c+1 \{ c equ x macro m\#y a \} } macro listx_list id { rept c y:id*1000000+1 \{ m\#y \} } PS. Yes, I see that those empty lines in preprocessor is something that perhaps deserves optimizing. You would then not get those lines in the preprocessed source in .fas file, but would that really be a problem? |
|||
04 Oct 2010, 07:58 |
|
revolution 04 Oct 2010, 08:55
Extreme unreadableness and maximum number of lines:
Code: macro b n{local m,c c equ 0 macro .#n[a]\{\common rept 1 x:c+1\\{c equ x macro m\\#x a\\}\}macro n#_\{rept c x\\{m\\#x\\}\}} b l rept 19350 x{.l\{db`x,0\}}l_ fasm -m10000 ListBuilderObfuscated.asm wrote: flat assembler version 1.69.24 (10000 kilobytes memory) |
|||
04 Oct 2010, 08:55 |
|
revolution 16 Oct 2010, 03:22
Latest fasm version 1.69.25
WHATSNEW.TXT wrote: version 1.69.25 (Oct 11, 2010) |
|||
16 Oct 2010, 03:22 |
|
vid 16 Oct 2010, 08:55
So, what's the top score so far?
|
|||
16 Oct 2010, 08:55 |
|
revolution 16 Oct 2010, 12:41
Just for vid:
Code: 1.69.24 1.69.25 ListBuilder1.asm 1430 1450 ListBuilder2.asm 13767 19693 ListBuilderMacro.asm 13480 19111 ListBuilderTomasz.asm 15311 19996 ListBuilderObfuscated.asm 19350 20205 |
|||
16 Oct 2010, 12:41 |
|
sid123 30 Dec 2014, 03:58
Hello,
I read this post by revolution, which introduces list building functionality in fasm through macros (http://board.flatassembler.net/topic.php?t=12012). I'm using them to store sections in proper order in my program, and here's how the header looks like: Code: ; Changed the name to not make it look out of context macro DECLARE_SECTION name { local m,c c equ 0 macro .#name [a] \{ \common rept 1 x:c+1 \\{ c equ x macro m\\#x a \\} \} macro STORE_SECTION_#name \{ rept c x \\{ m\\#x \\} \} } DECLARE_SECTION text DECLARE_SECTION data DECLARE_SECTION bss _text: STORE_SECTION_text _end_text: _data: STORE_SECTION_data _end_data: _bss: STORE_SECTION_bss _end_bss: However I have a problem, this works fine when I have something like this: Code: .text \{ mov ax, 0xff \} But as soon as I go multi-line... Code: .text \{ mov ax, 0xff mov bx, 0xfe ; Just a random example \} FASM shows an error displaying: Quote: .text \{ _________________ "Those who can make you believe in absurdities can make you commit atrocities" -- Voltaire https://github.com/Benderx2/R3X XD |
|||
30 Dec 2014, 03:58 |
|
revolution 30 Dec 2014, 06:03
Don't use the backslash (\) unless the line it is inside another macro.
Moved last post and this post into the actual topic. |
|||
30 Dec 2014, 06:03 |
|
sid123 30 Dec 2014, 09:01
Thanks revolution, works fine now!
|
|||
30 Dec 2014, 09:01 |
|
revolution 30 Dec 2014, 09:12
Just to be clear: For both cases you posted (single line and multi-line) there should be no backslash.
|
|||
30 Dec 2014, 09:12 |
|
l_inc 30 Dec 2014, 15:21
I hope, it's clear that newer fasm capabilities allow for a more efficient usage of memory than the provided macros do. Only the ampersand-feature allows to increase the number of strings by a couple of thousands. If we combine that with an irpv based counter, we could get over 30k:
Code: macro list_builder name { local c,m macro name a& \{ c equ macro m a \} macro name#.put \{irpv v,c \\{m purge m\\} \} } list_builder list1 rept 32496 x { list1 \{ db`x,0 \} } list1.put An "obfuscated" version: Code: macro b n{local c,m macro n a&\{c equ macro m a\}macro n#_\{irpv v,c\\{m purge m\\}\}} b l rept 33053 x {l\{db`x,0\}}l_ It should be noted however, that the usage of purge significantly increases the compilation time. _________________ Faith is a superposition of knowledge and fallacy |
|||
30 Dec 2014, 15:21 |
|
revolution 30 Dec 2014, 15:32
A nice use of the new capabilities.
|
|||
30 Dec 2014, 15:32 |
|
revolution 31 Dec 2014, 03:14
l_inc wrote: I hope, it's clear that newer fasm capabilities allow for a more efficient usage of memory than the provided macros do. Only the ampersand-feature allows to increase the number of strings by a couple of thousands. If we combine that with an irpv based counter, we could get over 30k: |
|||
31 Dec 2014, 03:14 |
|
revolution 31 Dec 2014, 03:28
So using the new irpv and & syntaxes we can do this for a forward ordered list:
Code: macro list_builder name { local c macro .#name a& \{ \local m c equ m macro m a \} macro name#_list \{ irpv v,c \\{ v \\} \} } list_builder list1 rept 19814 x { .list1 \{ db `x,0 \} } list1_list Code: macro reverse_list_builder name { local c macro .#name a& \{ \local m c equ m macro m a \} macro name#_list \{ irpv v,c \\{ \\reverse v \\} \} } reverse_list_builder list2 rept 19813 x { .list2 \{ db `x,0 \} } list2_list |
|||
31 Dec 2014, 03:28 |
|
baldr 31 Dec 2014, 08:33
revolution,
irpv effectively makes list building efforts unnecessary, unless you have to index into that list. |
|||
31 Dec 2014, 08:33 |
|
revolution 31 Dec 2014, 09:37
baldr wrote: revolution, |
|||
31 Dec 2014, 09:37 |
|
l_inc 31 Dec 2014, 12:58
revolution
Quote: I just realised that this outputs the list in reverse order! I know. Quote: It may, or may not, be a desired feature. I'd assume in most cases it's irrelevant rather than desired or not. But I must admit I'd prefer it to be in forward order. Quote: So using the new irpv and & syntaxes we can do this for a forward ordered list That was my first version, but it didn't beat the best scores. So I gave up on it. It would be cool to find a way for forward ordering with a score over 30k. _________________ Faith is a superposition of knowledge and fallacy |
|||
31 Dec 2014, 12:58 |
|
revolution 31 Dec 2014, 14:34
l_inc wrote: I'd assume in most cases it's irrelevant rather than desired or not. But I must admit I'd prefer it to be in forward order. l_inc wrote: It would be cool to find a way for forward ordering with a score over 30k. |
|||
31 Dec 2014, 14:34 |
|
revolution 07 Mar 2017, 07:25
I recently encountered a problem with some list builder code using the latest version of fasm. There is a name clash with the local name being concatenated with the counter. Previous versions of fasm would generate local names by appending a fixed length counter. Something like 'm' becoming 'm?0000123'. But current versions append a variable length string. Something like 'm' becoming 'm?B6p'. So when appending the counter we can have name clashes. So 'm?A34' could be either the base name 'm?A3' with '4' appended, or be the base name 'm?A' with '34' appended.
To fix this I added an underscore (_) within the concatenation: Code: macro list_builder name { local m,c ;avoid name clashing c equ 0 ;initialise the counter macro .#name [a] \{ \common rept 1 x:c+1 \\{ c equ x ;update the counter macro m#_\\#x a ;open the macro \\} \} macro name#_list \{ rept c x \\{ m#_\\#x ;replay each line \\} \} } As an aside, why does the forum code keep altering the tabs within messages and making old posts appear unaligned and ugly? |
|||
07 Mar 2017, 07:25 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.