What Is Segment Register Pdf
In computing, a data segment (often denoted .data) is a portion of an object file or the respective address space of a program that contains initialized static variables, that is, global variables and static local variables. The size of this segment is determined by the size of the values in the program's source code, and does not change at run time.
The data segment is read/write, since the values of variables can be altered at run time. This is in contrast to the read-only data segment ( rodata segment or .rodata), which contains static constants rather than variables; it besides contrasts to the code segment, also known as the text segment, which is read-only on many architectures. Uninitialized information, both variables and constants, is instead in the BSS segment.
Historically, to be able to back up memory accost spaces larger than the native size of the internal address register would allow, early CPUs implemented a system of segmentation whereby they would shop a small set of indexes to utilize as offsets to certain areas. The Intel 8086 family of CPUs provided four segments: the code segment, the data segment, the stack segment and the extra segment. Each segment was placed at a specific location in retention by the software beingness executed and all instructions that operated on the information within those segments were performed relative to the get-go of that segment. This allowed a xvi-scrap address register, which would normally be able to admission 64 KB of memory space, to admission 1 MB of memory space.
This segmenting of the memory infinite into detached blocks with specific tasks carried over into the programming languages of the day and the concept is even so widely in use within modern programming languages.
Program memory [edit]
A reckoner programme memory can exist largely categorized into ii sections: read-only and read/write. This distinction grew from early systems belongings their principal program in read-only retentivity such every bit Mask ROM, EPROM, PROM or EEPROM. As systems became more complex and programs were loaded from other media into RAM instead of executing from ROM, the idea that some portions of the program'south retention should non be modified was retained. These became the .text and .rodata segments of the program, and the remainder which could be written to divided into a number of other segments for specific tasks.
Lawmaking [edit]
The code segment, also known as text segment, contains executable lawmaking and is generally read-only and fixed size.
Data [edit]
This shows the typical layout of a simple computer's program retention with the text, diverse data, and stack and heap sections.
The data segment contains initialized static variables, i.east. global variables and local static variables which take a divers value and can be modified. Examples in C include:
int i = iii; char a[] = "Hello World";
The values for these variables are initially stored within the read-but memory (typically inside the lawmaking segment) and are copied into the data segment during the commencement-up routine of the program.
BSS [edit]
The BSS segment contains uninitialized static data, both variables and constants, i.e. global variables and local static variables that are initialized to nix or do non have explicit initialization in source code. Examples in C include:
static int i; static char a[12];
Heap [edit]
The heap segment contains dynamically allocated memory, commonly begins at the end of the BSS segment and grows to larger addresses from there. It is managed by malloc, calloc, realloc, and free, which may use the brk and sbrk system calls to adjust its size (note that the use of brk/sbrk and a single heap segment is not required to fulfill the contract of malloc/calloc/realloc/free; they may too be implemented using mmap/munmap to reserve/unreserve potentially non-contiguous regions of virtual memory into the process' virtual address space). The heap segment is shared by all threads, shared libraries, and dynamically loaded modules in a process.
Stack [edit]
The stack segment contains the call stack, a LIFO structure, typically located in the higher parts of memory. A "stack pointer" register tracks the tiptop of the stack; it is adjusted each time a value is "pushed" onto the stack. The set of values pushed for i function phone call is termed a "stack frame". A stack frame consists at minimum of a return address. Automatic variables are also allocated on the stack.
The stack segment traditionally adjoined the heap segment and they grew towards each other; when the stack pointer met the heap arrow, costless memory was exhausted. With big accost spaces and virtual retention techniques they tend to be placed more freely, but they yet typically grow in a converging management. On the standard PC x86 architecture the stack grows toward accost zero, meaning that more than recent items, deeper in the call concatenation, are at numerically lower addresses and closer to the heap. On some other architectures information technology grows the contrary direction.
Interpreted languages [edit]
Some interpreted languages offer a similar facility to the data segment, notably Perl[1] and Ruby.[2] In these languages, including the line __DATA__
(Perl) or __END__
(Ruby, old Perl) marks the end of the code segment and the start of the data segment. Merely the contents prior to this line are executed, and the contents of the source file after this line are bachelor as a file object: PACKAGE::Information
in Perl (e.g., chief::Information
) and Information
in Ruby. This can be considered a course of here document (a file literal).
See also [edit]
- Segmentation (retention)
- Segmentation mistake
- Linker (computing)
- Code segment
- .bss
- Uninitialized variable
- Stack (abstract data blazon)
- Process command block
References [edit]
- ^ perldata: Special Literals
- ^ Ruby: Object: __END__
External links [edit]
- "C startup". bravegnu.org.
- "mem_sequence.c - sequentially lists memory regions in a procedure". Archived from the original on 2009-02-02.
- van der Linden, Peter (1997). Expert C Programming: Deep C Secrets (PDF). Prentice Hall. pp. 119ff.
What Is Segment Register Pdf,
Source: https://en.wikipedia.org/wiki/Data_segment
Posted by: goldsteinjact1966.blogspot.com
0 Response to "What Is Segment Register Pdf"
Post a Comment