Inês Jorge
Inês Jorge

Reputation: 19

Assembly Segment overlapping calculation

Values of each segment's pointers

In an Assembly program, knowing the values of all my segments and where they start, how can I know if they are overlapping each other?
For instance, in the image I have the values of the logical addresses. Does each segment have a predefined space that it will take? Or not? And how much space?

Upvotes: 1

Views: 1184

Answers (1)

Sep Roland
Sep Roland

Reputation: 39166

The numbers in your screenshot must come from a very small .EXE.
The segments that you declare in your program are logical subdivisions that help to structure the code.
In real address mode, the segments that the CPU sees are blocks of memory that contain 65536 bytes. Those 65536 bytes are equivalent to 4096 chunks of 16 bytes aka paragraphs.

Below, each 'x' stands for 16 bytes. You can see that there's a huge overlap between the segments in your example.

                   65280 bytes overlap between ES and CS
                <----------------------------------------->   
xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ... xxxxxxx
^               xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx ... xxxxxxxxxxxxxxxxxxxxxxx
ES              ^ xxxxxxxxxxxxxxxxxxxxxxxxxxxxx ... xxxxxxxxxxxxxxxxxxxxxxxxx
               CS ^
                  DS/SS
                  <------------------------------------------------------->
                           65504 bytes overlap between CS and DS/SS

knowing the values of all my segments and where they start, how can I know if they are overlapping each other?

If the values in in any two segment registers differ by less than 4096, then there will be overlap between them.

  2F37h  DS
- 2F35h  CS
 ------
     2   Difference is less than 4096, so there's overlap

Overlap is 4096 - 2 = 4094 paragraphs (4094 * 16 = 65504 bytes)

Upvotes: 2

Related Questions