简体   繁体   中英

Assembly language: The different segments…are they stored in the RAM?

I am new to assembly language. Whenever I initialize a memory segment for example: a code segment or a data segment, it is said that the OS allocates a portion of the memory for that. However, I am really confused by what my book means by "portion of memory". Is the code segment in the RAM to be specific?

You've got a number of references in the comments, but I wanted to add that there are different states to consider in answering your core questions:

  1. When you compile and link your code, it writes and stores the result to disk as an executable or library.
  2. In the disk image, the compiler/linker encodes information about the various segments.
  3. When the executable/library is loaded, the OS sets up the segments you declared into RAM and marks the memory pages that the segments occupy with the appropriate privileges (as noted by fuz ).
  4. Whether or not the entire content of a segment is read and loaded into RAM depends on numerous factors and optimizations offered by the platform you are running on. You can research that elsewhere...

Yes! Typically, all segments are loaded into RAM. we distinguish various segments for efficiency and security reasons. For example, we distinguish text and data because text is executable but not writable whereas data is writable but not executable.

On embedded platforms, some sections might live in an EEPROM or flash ROM instead of RAM so they don't waste precious RAM. For the programmer, the only difference is that you can't write to such sections unless you do some special preparations.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM