flat assembler
Message board for the users of flat assembler.
Index
> Programming Language Design > Grouping source sections with fasmg |
Author |
|
Tomasz Grysztar 10 Feb 2022, 17:43
Isn't it just another variation on the "globals" concept, like the IncludeIGlobals/IncludeUGlobals from Fresh project? And these macros were for fasm 1 already. Although with fasmg it is possible to make it more capable, with forward referencing possibility.
I have also mentioned the macro stacking solution in the "How can multiple sections of file be generated in parallel?" section of supplementary documentation, but I have not given any examples there, perhaps I should. But this is something that is likely even better done with CALM. |
|||
10 Feb 2022, 17:43 |
|
bitRAKE 10 Feb 2022, 19:00
Ah, do you mean this example:
Code: include '8086.inc' org 100h jmp CodeSection DataSection: virtual Data:: end virtual postpone virtual Data load Data.OctetString : $ - $$ from $$ end virtual end postpone db Data.OctetString CodeSection: virtual Data Hello db "Hello!",24h end virtual mov ah,9 mov dx,Hello int 21h virtual Data ExitCode db 37h end virtual mov ah,4Ch mov al,[ExitCode] int 21h Making things more difficult than they need to be perhaps. _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
10 Feb 2022, 19:00 |
|
Tomasz Grysztar 10 Feb 2022, 20:10
bitRAKE wrote: Ah, do you mean this example With CALM, it could be something like: Code: define collections macro? collect? name* calminstruction name local tmp reverse: take tmp, collections.name jyes reverse execute: take collections.name, tmp jno done assemble collections.name jump execute done: end calminstruction calminstruction ?! line& match =end? =collect?, line jyes close take collections.name, line exit close: arrange line, =purge ? assemble line end calminstruction end macro Code: collect strings caption db "Caption",0 end collect collect strings message db "Message",0 end collect strings And here's a variant that allows to put "strings" block before the collected parts are defined: Code: define collections macro? collect? name* if ~ defined collections..name restore collections..name define collections..name calminstruction collections..name local tmp reverse: take tmp, collections.name jyes reverse execute: take collections.name, tmp jno done assemble collections.name jump execute done: end calminstruction define collections.name macro name: postpone define collections.name end macro collections..name end postpone end if calminstruction ?! line& match =end? =collect?, line jyes close take collections.name, line exit close: arrange line, =purge ? assemble line end calminstruction end macro Code: define collections macro collect?! name* local new if defined collections.name macro name name new end macro else collections.name = 0 macro name new end macro end if collections.name = collections.name + 1 esc macro new end macro macro end?.collect?! esc end macro end macro Code: define collections macro collect?! name* local new, previous match :s:, collections.name macro previous! s end macro else macro previous! end macro postpone match :s:, collections.name macro name s end macro end match end postpone end match restore collections.name define collections.name :new: esc macro new previous end macro macro end?.collect?! esc end macro end macro |
|||
10 Feb 2022, 20:10 |
|
bitRAKE 25 Mar 2022, 21:40
These techniques work beautifully in:
Code: macro lea? line& match any=,=<values=>,line local name collect _CONST_ label name values end collect lea any,[name] else lea line end match end macro macro _T line& TCHAR line,0 end macro Code: lea rax,<_T "bitRAKE"> Code: ex1.asm [60]: lea rax,<_T'bitRAKE'> macro lea? [9]: lea line Processed: lea rax,<_T'bitRAKE'> Error: missing closing chevron. _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
25 Mar 2022, 21:40 |
|
Tomasz Grysztar 26 Mar 2022, 11:13
bitRAKE wrote: I can use syntax like: Code: include 'win64ax.inc' include 'globstr_reuse.inc' ; the second version from the "Global strings" thread include 'inline.inc' macro fastcall?.inline_string var local data match value, var data GLOBSTR value,0 end match redefine var data end macro inlinemacro GLOB(value) local data data GLOBSTR value,0 return equ data end inlinemacro .code start: invoke MessageBox,HWND_DESKTOP,'First!',"Demo",MB_OK lea rdx,[GLOB("Second!")] invoke MessageBox,HWND_DESKTOP,rdx,"Demo",MB_OK invoke ExitProcess,0 .data GLOBSTR.here .end start bitRAKE wrote: but I get some strange errors without the space between _T and the quote/apostrophe character. Not a show stopper - just curious why fasmg would come back with: |
|||
26 Mar 2022, 11:13 |
|
bitRAKE 27 Mar 2022, 08:09
It's not an error in fasmg. I forgot that _T"test": is a valid label name. So, I need the space to split them. I was happy when it didn't prune the <> and I was able to detect that syntax.
_________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
27 Mar 2022, 08:09 |
|
bitRAKE 29 Mar 2022, 10:37
Originally, I tried:
Code: struc TD_BUTTONS line& local name collect _CONST_ iterate <quoted,id>,line align sizeof.TCHAR label name.% TCHAR quoted,0 if % = %% . equ name align 4 label name:%% repeat %% indx % dd id dq name.% end repeat end if end iterate end collect end struc Code: _CONST_ [10] macro TCHAR [1] du? [14] macro WCHAR [2]: if arg eqtype '' Processed: if quoted eqtype '' Error: symbol 'quoted' is undefined or out of scope. |
|||
29 Mar 2022, 10:37 |
|
Tomasz Grysztar 29 Mar 2022, 11:28
bitRAKE wrote: It's like the ITERATE doesn't have all the code to update symbols. Another workaround: use conditional interceptor instead of unconditional one ("?" instead of "?!"). This way things like IF or ITERATE would be evaluated before collecting. This would require modifications of how "end collect" is detected: Code: define collections macro collect? name* calminstruction name local tmp reverse: take tmp, collections.name jyes reverse execute: take collections.name, tmp jno done assemble collections.name jump execute done: end calminstruction calminstruction ? line& match /=collect?, line jyes close take collections.name, line exit close: arrange line, =purge ? assemble line end calminstruction end macro macro end?.collect?! /collect end macro |
|||
29 Mar 2022, 11:28 |
|
bitRAKE 29 Mar 2022, 15:32
The single use macro seems very flexible:
Code: struc TD_BUTTONS line& local name struc name.struc iterate <quoted,id>,line align sizeof.TCHAR label name.% TCHAR quoted,0 if % = %% . equ name align 4 label name:%% repeat %% indx % dd id dq name.% end repeat end if end iterate end struc collect _CONST_ . name.struc end collect end struc Code: _CONST_ [10] Processed: indx 1 Error: unexpected instruction. _________________ ¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup |
|||
29 Mar 2022, 15:32 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.