I apologize in advance if this question is considered too trivial, but I spent a lot of time trying to find a direct answer online and could not.
Recently I read in the programming class an intro on program segmentation and how usually programs are divided into "segments" that are individually loaded into memory (or partially loaded into memory, via paging ... I think) when necessary. In our book, it was mentioned that programs are often divided into segments based on logical divisions, for example. segment for stack, for heap, for global constants, etc.
I wonder what exactly determines how this segmentation works. Is this done by the compiler at compile time? Or does the OS somehow handle this? Does each subroutine always get its own segment, no matter how small it is?
I know that information related to segmentation, such as segment descriptors, etc., is processed at the architecture level using registers and is specifically designed to work with segmentation. But I just have a lot of problems when I see where / how the actual segmentation of the program occurs, and how this information falls into these registers. How do addresses translate into segment identifiers and offsets? Can anyone enlighten me? Thank you so much for any help you can give and I'm sorry if I included any concepts in it.
source
share