flat assembler
Message board for the users of flat assembler.
Index
> Main > Organizing macros in modules |
Author |
|
macomics 22 Feb 2022, 06:43
For macros, use "match"
|
|||
22 Feb 2022, 06:43 |
|
Chaeremon 22 Feb 2022, 07:00
The virtual sym thing can come from any file (bringing additions to modules) in any order.
|
|||
22 Feb 2022, 07:00 |
|
macomics 22 Feb 2022, 07:06
virtual declares a separate addressing space. And, in my opinion, at the assembler level. What happens after the preprocessor at which macros are processed. Moreover, neither macros nor structures affect the current address space until they are used (not declared). Example of using virtual in combination with structures (read macros):
Code: struc GDTR offset, length { local .temp . dp .temp and 0x00FFFFFF virtual at . .length dw length - 1 .offset dd offset, 0 load .temp qword from . end virtual } newGDTR GDTR GDT, GDT_end - GDT GDT: ... ; descriptors GDT_end: mov cx, [newGDTR.length] mov esi, [newGDTT.offset] lgdt [newGDTR] |
|||
22 Feb 2022, 07:06 |
|
Chaeremon 22 Feb 2022, 07:56
... what part is module declaration and what part is model member (element) use? And how's that pulled together from arbitrary .inc files ...
I'm not going to respond to address space, this is left to macro user. |
|||
22 Feb 2022, 07:56 |
|
macomics 22 Feb 2022, 08:13
But macros are not declared as binary data and are processed at the source code level. And virtual blocks work with the address space of the output file. They isolate part of this space and prevent its inclusion in the final output file. I.e., the name of the declared macro is not mapped to the address and is processed at the text level every time it is used in the source code location where it was used. If you want to exclude some unused macros from the source text, then you should use something like this:
Code: ; main.asm define ALLMYMACRO used define MYMACRO0 unused define MYMACRO1 used match =used ALLMYMACRO { include "allmymacro.inc" } Code: ; allmymacro.inc match =used,MYMACRO0 { include "mymacro0.inc" } ; excluded match =used,MYMACRO1 { include "mymacro1.inc" } ; included Code: ; mymacro0.inc macro mymacro0 ... Code: ; mymacro1.inc macro mymacro1 ... You can of course do it this way Code: ; allmymacro.inc match =used,MYMACRO0 { macro mymacro0 ... } macth =used,MYMACRO1 { macro mymacro1 ... } Last edited by macomics on 22 Feb 2022, 08:34; edited 1 time in total |
|||
22 Feb 2022, 08:13 |
|
Chaeremon 22 Feb 2022, 08:24
Do you agree that match is useless because,
macomics wrote: unused macros will be excluded. What I wrote above: 1. declare a module in some wanted (arbitrary) environment; 2. append (arbitrary) things to the module if wanted/needed, maybe .inc files or your own addition. 3. use from the named module what you want. _________________ An overabundance of Smalltalk platforms doesn't exist, just start writing the next core in flatassembler. |
|||
22 Feb 2022, 08:24 |
|
macomics 22 Feb 2022, 08:51
Chaeremon wrote: What I wrote above: 1. declare a module in some wanted (arbitrary) environment; 2. append (arbitrary) things to the module if wanted/needed, maybe .inc files or your own addition. 3. use from the named module what you want. Code: format binary Test1: macro .Point X*, Y*, Z* { dq X, Y, Z } macro Test1.Point X, Y { dd X, Y } Test1.Point 0, 0 .Point 1, 2, 3 ;flat assembler version 1.73.29 (16384 kilobytes memory) ;1 passes, 0.3 seconds, 32 bytes. |
|||
22 Feb 2022, 08:51 |
|
revolution 22 Feb 2022, 09:16
Yeah, the two stage thing needs to be considered correctly.
Stage 1. All macros (rept, irp, struc, ...) and label names (but not their values) are defined. No instructions or virtual blocks are processed, they are completely ignored. Stage 2: Assemble instructions and virtual blocks. All macros blocks are completely ignored, the macros have already done their part. [edit] Changed "pass" to "stage" Last edited by revolution on 22 Feb 2022, 15:29; edited 3 times in total |
|||
22 Feb 2022, 09:16 |
|
revolution 22 Feb 2022, 09:19
For example this file will assemble without error:
Code: virtual at 0 db 1 macro foo { db 2 end virtual } end virtual virtual at 0 foo [edit] Changed "pass" to "stage" Last edited by revolution on 22 Feb 2022, 15:30; edited 1 time in total |
|||
22 Feb 2022, 09:19 |
|
macomics 22 Feb 2022, 09:31
revolution wrote: macro foo is defined in pass 1 and has no effect on the first virtual block in pass 2. |
|||
22 Feb 2022, 09:31 |
|
Chaeremon 22 Feb 2022, 09:48
Try (in my example) without the sym. in the virtual sym thing. So the talk can be about that thing.
P.S. I thought about your match thing, macros invoke each other, can even pass macros as argument. No match thing can know that. |
|||
22 Feb 2022, 09:48 |
|
Tomasz Grysztar 22 Feb 2022, 09:55
Chaeremon wrote: But the macro name appears to have its own rules (other than rules for labels). Chaeremon wrote: If the below can be made more fasm-like I'd love to see suggestions for modular organization. I altered your sample to show how you'd do it with fasmg: Code: section '.NaVM' code executable readable sym: ; define a module's parent namespace sym ; tell which module to enter macro test arg align arg end macro end namespace sym.test 2 That being said, you could perhaps make a simplified framework for handling modules with fasm 1, doing something like this: Code: macro module name { define __MODULE__ name } macro mmacro decl& { local d define d decl match module, __MODULE__ \{ match name rest, d \\{ macro name args& \\\{ module\#.\\#name args \\\} macro module\#.\\#name rest \\} \} } module sym mmacro test arg { align arg } sym.test 2 Last edited by Tomasz Grysztar on 22 Feb 2022, 10:19; edited 1 time in total |
|||
22 Feb 2022, 09:55 |
|
revolution 22 Feb 2022, 09:58
macomics wrote:
Chaeremon wrote: Try (in my example) without the sym. in the virtual sym thing. So the talk can be about that thing Virtual blocks are entirely ignored during the first stage. So you can't have macro names be part of the virtual block in any way. The code simply doesn't exist in the assembler. Macro names are in a separate part of the assembler memory from program labels memory. They never mix together. [edit] Changed "pass" to "stage" Last edited by revolution on 22 Feb 2022, 15:31; edited 1 time in total |
|||
22 Feb 2022, 09:58 |
|
Tomasz Grysztar 22 Feb 2022, 10:03
revolution wrote: This is related to the two passes. |
|||
22 Feb 2022, 10:03 |
|
macomics 22 Feb 2022, 10:27
To make it clearer what you want - let's give examples that do not consist of separate pieces.
|
|||
22 Feb 2022, 10:27 |
|
Chaeremon 22 Feb 2022, 10:41
Quote:
Wasn't aware they can reference macros like you show, so I'm going to make modules with their own namespace. Thank you Tomasz. |
|||
22 Feb 2022, 10:41 |
|
macomics 22 Feb 2022, 14:59
He just needs to add a prefix to the macro name. Maybe I didn't understand something. I'll ask you directly. Where are the modules here?
|
|||
22 Feb 2022, 14:59 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.