News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

_BSS and STACK Segment Order

Started by dedndave, January 09, 2012, 03:27:19 AM

Previous topic - Next topic

dedndave

i learned something new about Masm, when building 16-bit projects   :P

as usual, i started a program like this...
        .MODEL  Small
        .STACK  1024

        .DATA

;some initialized data stuff

        .DATA?

;some uninitialized data stuff

        .CODE

;some code stuff

in the code, i calculated the end of the program's memory by using SS:SP
much to my surprise, i found that the segment order was:
_TEXT
_DATA
STACK
_BSS
and of course, DGROUP included the _DATA, STACK, and _BSS segments
i knew that DGROUP included the STACK segment, but did not know that it was jammed in between _DATA and _BSS
i modified the program a little, as follows:
        .MODEL  Small

        .DATA

;some initialized data stuff

        .DATA?

;some uninitialized data stuff

        .STACK  1024

        .CODE

;some code stuff

and all is right with the world   :P
the new segment order is:
_TEXT
_DATA
_BSS
STACK

back in the day, when i wrote a lot of 16-bit code using MASM version 5.10,
i always opened and closed segments using SEGMENT - i never used the .DATA/.CODE shortcuts
i determined which segments were in DGROUP with a GROUP directive
when you do it that way, you have complete control over segment order
they appear in the program in the order in which they are first opened

sinsi

Light travels faster than sound, that's why some people seem bright until you hear them.

dedndave

thanks, Sinsi
not that i am writing any 16-bit libraries - lol
but the masm manual says not to use .DOSSEG in any module that is to be called by another module
not sure why that is   :P
probably because the segment order is controlled by the calling module
at any rate, i had forgotten about that one   :bg

i wound up with this...
        .MODEL  Small
        .CODE
        .DATA
        .DATA?
        .STACK  1024            ;ensure that STACK is highest segment

        .DATA

;some initialized data stuff

        .DATA?

;some uninitialized data stuff

        .CODE

;some code stuff


i wanted to control the segment order - and i wanted it to be highly visible
i also prefer the .STACK directive be near the beginning of the file, where it belongs