flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > List operations macros.

Author
Thread Post new topic Reply to topic
MHajduk



Joined: 30 Mar 2006
Posts: 6115
Location: Poland
MHajduk 03 Feb 2007, 20:21
I hope, that this set of macros designed for list operations will be interesting for You, because I haven't seen similar macros here. Very Happy

Below is a description of each macro. Note that:
  • result of each macro preprocessing is stored in symbolic constant 'Result',
  • list elements are numbered from 0.
Macro which returns first element of a given list.

Usage: Head <list>
Code:
macro   Head firstEl, [list]
{
        common
        Result  equ firstEl
}    
Macro which returns tail of a given list, i.e. all elements except first (with number 0).

Usage: Tail <list>
Code:
macro   Tail firstEl, [list]
{
        common
        Result  equ list
}    
Macro which returns n-th element (zero based) from a given list.

Usage: Element, <el_number>, <list>
Code:
macro   Element n, [list]
{
        common

        Result  equ list

        rept n
        \{
                match   L, Result \\{Tail L\\}
        \}

        match   L, Result \{Head L\}
}    
Macro which returns a sublist of a given list from n-th element (including this element).

Usage: TailFrom <first_sublist_el_num>, <list>
Code:
macro   TailFrom n, [list]
{
        common

        Result  equ list

        rept n
        \{
                match   L, Result \\{Tail L\\}
        \}
}    
Macro which returns a sublist of a given list from 0 element to n-th element (including this element).

Usage: HeadTo <last_sublist_el_number>, <list>
Code:
macro   HeadTo n, [list]
{
        common

        Result  equ

        match   L, list \{Head L\}
        headTmp equ Result

        match   L, list \{Tail L\}

        rept n
        \{
                tailTmp equ Result

                match   L, tailTmp \\{Head L\\}
                match   L, Result  \\{headTmp equ headTmp, L\\}

                match   L, tailTmp \\{Tail L\\}
        \}

        Result equ headTmp
}    
Macro which returns a sublist of a given list (from m-th to n-th element, including these border elements).

Usage: SubList <first_sublist_el_num>, <last_sublist_el_num>, <list>
Code:
macro   SubList m, n, [list]
{
        common

        HeadTo  n, list
        match   L, Result \{TailFrom m, L\}
}    
Here is a simple example of using these macros:
Code:
; Example of using list operations macros
; (run with FASM preprocessor - 'fasmpre.exe').
;
; (C) Mikolaj Hajduk, 03.02.2007.
;
include 'ListMacros.inc'

SubList 3,6,a,b,c,d,e,f,g,h

Result    
Result of preprocessing this file by FASM preprocessor (fasmpre.exe):
Code:




;include 'ListMacros.inc'
















;macro Head firstEl,[list]
;{
; common
; Result equ firstEl
;}






;macro Tail firstEl,[list]
;{
; common
; Result equ list
;}





;macro Element n,[list]
;{
; common
;
; Result equ list
;
; rept n
; \{
; match L,Result \\{ Tail L \\}
; \}
;
; match L,Result \{ Head L \}
;}






;macro TailFrom n,[list]
;{
; common
;
; Result equ list
;
; rept n
; \{
; match L,Result \\{ Tail L \\}
; \}
;}






;macro HeadTo n,[list]
;{
; common
;
; Result equ
;
; match L,list \{ Head L \}
; headTmp equ Result
;
; match L,list \{ Tail L \}
;
; rept n
; \{
; tailTmp equ Result
;
; match L,tailTmp \\{ Head L \\}
; match L,Result \\{ headTmp equ headTmp,L \\}
;
; match L,tailTmp \\{ Tail L \\}
; \}
;
; Result equ headTmp
;}






;macro SubList m,n,[list]
;{
; common
;
; HeadTo n,list
; match L,Result \{ TailFrom m,L \}
;}


;SubList 3,6,a,b,c,d,e,f,g,h


















;HeadTo 6,a,b,c,d,e,f,g,h


















;Result equ

;match L,a,b,c,d,e,f,g,h{Head L}
;Head a,b,c,d,e,f,g,h















;Result equ a

;headTmp equ a

;match L,a,b,c,d,e,f,g,h{Tail L}
;Tail a,b,c,d,e,f,g,h















;Result equ b,c,d,e,f,g,h


;rept 6
;{
; tailTmp equ Result
;
; match L,tailTmp \{ Head L \}
; match L,Result \{ headTmp equ headTmp,L \}
;
; match L,tailTmp \{ Tail L \}
;}

;tailTmp equ b,c,d,e,f,g,h

;match L,b,c,d,e,f,g,h{Head L}
;Head b,c,d,e,f,g,h













;Result equ b

;match L,b{headTmp equ headTmp,L}
;headTmp equ a,b

;match L,b,c,d,e,f,g,h{Tail L}
;Tail b,c,d,e,f,g,h













;Result equ c,d,e,f,g,h



;tailTmp equ c,d,e,f,g,h

;match L,c,d,e,f,g,h{Head L}
;Head c,d,e,f,g,h











;Result equ c

;match L,c{headTmp equ headTmp,L}
;headTmp equ a,b,c

;match L,c,d,e,f,g,h{Tail L}
;Tail c,d,e,f,g,h











;Result equ d,e,f,g,h



;tailTmp equ d,e,f,g,h

;match L,d,e,f,g,h{Head L}
;Head d,e,f,g,h









;Result equ d

;match L,d{headTmp equ headTmp,L}
;headTmp equ a,b,c,d

;match L,d,e,f,g,h{Tail L}
;Tail d,e,f,g,h









;Result equ e,f,g,h



;tailTmp equ e,f,g,h

;match L,e,f,g,h{Head L}
;Head e,f,g,h







;Result equ e

;match L,e{headTmp equ headTmp,L}
;headTmp equ a,b,c,d,e

;match L,e,f,g,h{Tail L}
;Tail e,f,g,h







;Result equ f,g,h



;tailTmp equ f,g,h

;match L,f,g,h{Head L}
;Head f,g,h





;Result equ f

;match L,f{headTmp equ headTmp,L}
;headTmp equ a,b,c,d,e,f

;match L,f,g,h{Tail L}
;Tail f,g,h





;Result equ g,h



;tailTmp equ g,h

;match L,g,h{Head L}
;Head g,h



;Result equ g

;match L,g{headTmp equ headTmp,L}
;headTmp equ a,b,c,d,e,f,g

;match L,g,h{Tail L}
;Tail g,h



;Result equ h



;Result equ a,b,c,d,e,f,g

;match L,a,b,c,d,e,f,g{TailFrom 3,L}
;TailFrom 3,a,b,c,d,e,f,g
















;Result equ a,b,c,d,e,f,g

;rept 3
;{
; match L,Result \{ Tail L \}
;}

;match L,a,b,c,d,e,f,g{Tail L}
;Tail a,b,c,d,e,f,g













;Result equ b,c,d,e,f,g



;match L,b,c,d,e,f,g{Tail L}
;Tail b,c,d,e,f,g











;Result equ c,d,e,f,g



;match L,c,d,e,f,g{Tail L}
;Tail c,d,e,f,g









;Result equ d,e,f,g





d,e,f,g


    
Regards.


Description: List operations macros with example of use and result of preprocessing.
Download
Filename: ListMacros.zip
Filesize: 1.65 KB
Downloaded: 263 Time(s)

Post 03 Feb 2007, 20:21
View user's profile Send private message Visit poster's website Reply with quote
dead_body



Joined: 21 Sep 2005
Posts: 187
Location: Ukraine,Kharkov
dead_body 04 Feb 2007, 19:27
interesting, but where can i use it?
Post 04 Feb 2007, 19:27
View user's profile Send private message Reply with quote
MHajduk



Joined: 30 Mar 2006
Posts: 6115
Location: Poland
MHajduk 05 Feb 2007, 08:11
dead_body:

I think, that it could be used to create parsers for other programming languages. Smile However using FASM preprocessor in that case may be "slightly" Wink difficult, because of absence 'split' macro.
Post 05 Feb 2007, 08:11
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.