flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Problem using complex # constructions |
Author |
|
Tomasz Grysztar 17 Aug 2009, 12:52
The = operator is an assembly-time operation, not preprocessor's one - therefore at the time the = is interpreted, all the preprocessing is already finished long time ago (see Understanding fasm for more details on this).
So you should use the symbolic variable (defined with "equ") instead of numerical one. And note, that to get the value of such variable available for concatenation you need to extract it with "match" directive (check out the documentation on this one, too). With fasm 1.69 you can do it like this: Code: macro example name,[array] { common ; init i equ 0 forward ; store values match value,i \{ _some_#name#_\#value\#_index = value \} rept 1 j:i+1 \{ i equ j \} common ; write header db i i equ 0 forward ; write values match value,i \{ db _some_#name#_\#value\#_index \} rept 1 j:i+1 \{ i equ j \} } example x,1,1,1,1,1,1 ; ignore the 1's they're just placeholders display '0'+_some_x_3_index ; tester, should display digit 3 |
|||
17 Aug 2009, 12:52 |
|
revolution 17 Aug 2009, 12:59
It is a bit complex to do like that because "i=0" is an assembler stage construction and the rest are pre-processor stage constructions.
It requires you to get up "i equ 0" and then to use match to map the name to the value for the variable name. Try this: Code: macro example name,[array] { common ; init i equ 0 forward ; store values match j,i \{_some_#name#_\#j\#_index = j \}; _some_x_i_index NOT _some_x_0_index etc ... match j,i \{ rept 2 k:j { i equ k \\} \} common ; write header db i i equ 0 forward ; write values match j,i \{ db _some_#name#_\#j\#_index \} match j,i \{ rept 2 k:j { i equ k \\} \} } example x,1,1,1,1,1,1 ; ignore the 1's they're just placeholders [edit] Tomasz Grysztar beat me to it, and made a better job of it than me. I still haven't updated myself with the latest fasm capabilities. It seems I am living in the past. |
|||
17 Aug 2009, 12:59 |
|
cod3b453 19 Aug 2009, 02:15
WOW - thank you both very much!
I'd never really grasped match before... I also like that rept trick Truely amazing how powerful macros can be. |
|||
19 Aug 2009, 02:15 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.