I am learning x86 assembly language, and I understand the purpose and usage of segments. Segments hold vital data, and can also be used to store extra data (ie. Memory Segmentation Model). Here is my question though. If segments can be used to store extra data, how can I make sure that my storing data in them won't overwrite any existing data?
For example, the CS register points to the Code Segment. The Code Segment contains the program's code. If I used the CS register with an offset to store some data, how would I know where to put my data so as not to overwrite the code that it is storing?
Please let me know. I using Intel syntax assembly and assembling with NASM.
Thanks
Segments never store any data. The segment registers are just "base" address pointers which are used to create 20-bit pointers using only 16-bit registers. For example:
As for your question how to make sure that you don't overwrite code with data: it's entirely up to you make sure that you know exactly where in memory you store your code and data!