user394334
user394334

Reputation: 277

ARM assembly: global variables the dynamic data segment or the global data segment

My book talks about the global data segment and the dynamic data segment. Here is a picture from my book: enter image description here

This makes me wonder about global variables? Where are global variables stored? It says that they are stored in the global data segment, but what if the variable is not known at start-up, then it should be in the dynamic data segment?

Upvotes: 0

Views: 415

Answers (1)

Tom V
Tom V

Reputation: 5510

Placing things in segments depends on when the memory is allocated, not when it is used or gets its value.

What this book is referring to as the global data segment is all the variables which are allocated their address at compile time.

What this book is referring to as the dynamic data segment is things which do not get their address assigned until run time.

However, as I explained when you posted almost exactly this same question previously, this book is not very good! In the real world the stack and heap are not usually lumped together as a single segment, they are two very different things and should be handled separately.

Having the heap grow up and stack grow down towards each other in the same block used to be a common way of maximizing available memory, and is still often used in (non safety critical) embedded systems, but more commonly now they are completely separate.

Also, the global variables are in many categories. Read-only global variables may actually be in the text segment, or in their own read-only data segment that this book doesn't seem to know about. Writeable global variables fall into two or three categories depending on whether they are zero-initialized, non-zero initialized, or uninitialized, and each of these has a separate segment name (typically .bss and .data for the first two and non-standardized name for uninitialized data).

Upvotes: 2

Related Questions