flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Splitting source code into sections: better ways?

Author
Thread Post new topic Reply to topic
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 28 Jul 2020, 13:20
Suppose I want to have each of my files have the following structure:
Code:
; Macros, constants, structure definitions, etc. go here



data    ; Initialized data

dwSomeValue     dd      42
MoreData        COMPLEXSTRUCT   1, 2, 3, <4, 5>



data?   ; Uninitialized data

dwMyData        dd      ?
MoreData        COMPLEXSTRUCT



code    ; Code

proc MyProc
     ret
endp    
The purpose is to avoid having multiple files for related stuff and to automate the process of gathering the pieces together at proper points in the main program. This part is an easy one.

The difficult part is about the syntax shown in the example. In fact, each of the “keywords” should wrap the text until the next “keyword” (or the end of file) into a macro. Which brings the problem of closing properly the preceding macro.

One easy solution is to transform each “keyword” into a macro header and use a slightly modified syntax:
Code:
data
{
dwSomeValue     dd      42
MoreData        COMPLEXSTRUCT   1, 2, 3, <4, 5>
}    


Another easy solution is to introduce a set of special closing “keywords”:
Code:
enddata fix }
enddata? fix }
endcode fix }
...    
and then use the “keywords” in pairs. Has additional problems if the file content is put into one or more preprocessor blocks.

Is the exact section-like syntax I’ve shown in the first example really implementable with FASM macros? Any ideas?
Post 28 Jul 2020, 13:20
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 28 Jul 2020, 13:40
DimonSoft wrote:
Is the exact section-like syntax I’ve shown in the first example really implementable with FASM macros? Any ideas?
Not exact, but see here:
https://board.flatassembler.net/topic.php?t=12012
Post 28 Jul 2020, 13:40
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 28 Jul 2020, 14:17
AFAICT, the method shown there is the easy solution #1 from my previous message. I wonder if there’s a way to get rid of the curly braces as well without introducing new “keywords”. I feel it is impossible, but maybe I miss something.
Post 28 Jul 2020, 14:17
View user's profile Send private message Visit poster's website Reply with quote
Overclick



Joined: 11 Jul 2020
Posts: 669
Location: Ukraine
Overclick 30 Jul 2020, 14:25
Post 30 Jul 2020, 14:25
View user's profile Send private message Visit poster's website Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 31 Jul 2020, 16:42
I feel leaving the choice of where to put code and data blocks for assembler stage is asking for trouble, especially when the content of the blocks is out of control.
Post 31 Jul 2020, 16:42
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.