Moon
Moon

Reputation: 22605

Why do we need to define .data and .text section in 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?

Upvotes: 20

Views: 17457

Answers (1)

Zuljin
Zuljin

Reputation: 2640

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.

Upvotes: 21

Related Questions