flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Does the macro preprocessing text ?

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1821
Roman 26 Mar 2023, 16:36
Fasmw 1.73
Code:
;macro getparams not using asm commands CPU.
;must load txt data as preprocessing and calculate how much %f in text.

macro getparams a,b {..
params equ count_input_params
}
txt db '[%f ,%f ,%f ,%f]',0 ;4 params %f

getparams txt,'%f' ;must do params equ 4
cinvoke sprintf,ebx,txt,params
    


I found in docs this.
Code:



 virtual at 0
        hex_digits::
        db '0123456789ABCDEF'
    end virtual
;but where is put byte load, and how do eq or if for this byte ?
    load a byte from hex_digits:10 

    

Another way get text to macro.
Code:
macro get a {}
get '[%f ,%f ,%f ,%f]'
;using match to cut all %f and find count
    
Post 26 Mar 2023, 16:36
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1004
Location: Russia
macomics 26 Mar 2023, 19:05
Code:
macro getparams a, b
{   local q, length, c, t, z, ptr
    virtual at 0
        db b
        ptr = $
        length db a
        params = 0
        load q byte from 0
        while ptr < $ - length
            load c byte from ptr
            if q = c
                params = params + 1
                repeat length - 1
                    load t byte from %
                    load z byte from (ptr + %)
                    if t <> z
                        params = params - 1
                        break
                    end if
                end repeat
            end if
            ptr = ptr + 1
        end while
    end virtual
}

getparams '[%f, %f, %f, %f]', '%f'
display params + '0', 13, 10

getparams '[%f, %x, %f, %d]', '%x'
display params + '0', 13, 10

getparams '[%i, %i, %i, %i]', '%d'
display params + '0', 13, 10    
Code:
 ~ $ fasm -m 1024 main.asm
flat assembler  version 1.73.30  (1024 kilobytes memory)
4
1
0
1 passes, 0 bytes.    


Last edited by macomics on 28 Mar 2023, 15:06; edited 2 times in total
Post 26 Mar 2023, 19:05
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1821
Roman 26 Mar 2023, 19:11
Thanks.
Its awesome !

But I try and get 0, not 4
getparams '[%f, %f, %f, %f]', '%f'
display params + '0', 13, 10


Last edited by Roman on 26 Mar 2023, 19:15; edited 1 time in total
Post 26 Mar 2023, 19:11
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1004
Location: Russia
macomics 26 Mar 2023, 19:15
Fixed the error. Updated the text above.
Post 26 Mar 2023, 19:15
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1821
Roman 26 Mar 2023, 19:17
Thanks.
Now work.
Post 26 Mar 2023, 19:17
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1821
Roman 28 Mar 2023, 10:38
macomics
I comment label count at $ - $$
And macro work.

Why using this in macro ?
Code:
 label count at $ - $$      
Post 28 Mar 2023, 10:38
View user's profile Send private message Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1004
Location: Russia
macomics 28 Mar 2023, 15:04
I initially counted the number of bytes for virtual without 'at 0'. It 's better to write like this there
Code:
label count at $ - length    
This is necessary so that there are no comparisons with the template outside of the search string.

ADD: However, you can completely get rid of it because the same expression is written immediately in the while loop
Post 28 Mar 2023, 15:04
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1821
Roman 28 Mar 2023, 16:06
I thinked count using as hidden parameter for while or repeat.
Post 28 Mar 2023, 16:06
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.