Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we need to define .data and .text section in assembly?

Tags:

assembly

I'm reading an assembly book. The book explains that there are .text and .data section in a computer's memory. An example in the book also use the following source code.

[SECTION .data]

[SECTION .text]

since the above code snippet is written in assembly, I have a question.

Do .data and .text codes separated in physical memory (if so why? and does CPU care?) ? or is it just us (human) to separate them in the assembly language?

like image 245
Moon Avatar asked Aug 31 '11 08:08

Moon


1 Answers

Text section of application is read-only while Data is not. Many OS load Text section into memory only once no matter how many times application was launched. This reduce memory usage and launch time and is safe because code doesn't change. Data section contains informations that could be changed during application execution and this section must be copied for every instance.

like image 85
Zuljin Avatar answered Sep 27 '22 23:09

Zuljin