Intel XENIX 286 Programmers Guide (86) - Tenox.tc

Intel XENIX 286 Programmers Guide (86) - Tenox.tc Intel XENIX 286 Programmers Guide (86) - Tenox.tc

09.06.2013 Views

XENIX Programming as: Assembler Assembly Segments as assembles instruction and data statements in three segments, text, data, and bss. Segments allow division of instructions and data into separate physical segments in memory. A location counter keeps the current address within each segment during assembly and provides reference to the current instruction and data. Text, Data, and Bss Segments Every program is divided into at most three distinct segments of assembled code and data: the text segment, the data segment, and the bss segment. Each segment is reserved for a specific type of storage and receives different treat ment from the assembler and from the XENIX linker when the final program is created. The text segment is normally reserved for instructions but may also be used for data. Instructions in this segment are assembled, and the code is copied to the output file. Data definitions in this segment are also assembled and copied; the code is the value of the data item. The assembler does not separate the instruction and data code. If the instructions and data definitions are mixed within the source file, the resulting code is mixed within the output file. The data segment is reserved for data. The code is copied to a different part of the output file and receives different treat ment from the XENIX linker. The bss segment is reserved for uninitialized data only. Instructions or data definitions with initial values must not be given in this segment. The assembler counts the nu mber of bytes allocated for this segment and copies this count to the output file. It does not generate code. The text segment is implicitly defined at the start of every assembly. Thus, any instructions or data definitions given when no other segment is explicitly defined are copied to the text segment. To start a data or bss segment, you must use a .data or .bss directive. You can explicitly start the text segment with the .text directive (see the section "Segment Directives," later in this chapter). Unless otherwise specified, the first statement in the text segment is considered the program's entry point. In shared-text programs, the instructions and data in the text segment are write-protected; in nonshared-text programs, they are not. Instructions and data in the data segment are never write-protected. The bss segment is actually an extension of the data segment. It begins immediately after the data segment and is initialized to 0 at the start of program execution. 7-3

as: Assembler XENIX Programming The Location Counter The special symbol "dot" (.) is the location counter. Its value at any time is the offset from the current statement to the start of the current segment. Thus, it may be used in any statement to refer to the current location. The location counter actually has three different offsets, one for each type of segment. Only the offset of the current segment is ever accessible. The assembler increments the current offset after it processes each statement. It increments the offset by the number of bytes in the assembled code or allocated storage. The location counter can be assigned an explicit value if desired. Its value must not be decreased. If it is explicitly increased, the assembler generates enough null bytes of code to fill the gap between the last offset and the new offset. Statements A source program is composed of a sequence of statements. Statements are separated by newline characters. There are four kinds of statements: • Null statements • Expression statements • Assignment statements • Keyword statements The format for most 8086/286 assembly language source statements is [ /abe/field ] op-code [ operand-field ] [ comment ] Any kind of statement may be preceded by one or more labels. Labels There are two kinds of labels: name labels and numeric labels. A name label consists of an identifier followed by a colon (:). The effect of a name label is to assign the current value and type of the location counter to the name. An error is indicated in pass 1 if the name is already defined; an error is indicated in pass 2 if the value assigned changes the definition of the label. 7-4

<strong>XENIX</strong> Programming as: Assembler<br />

Assembly Segments<br />

as assembles instruction and data statements in three segments, text, data, and bss.<br />

Segments allow division of instructions and data into separate physical segments in<br />

memory. A location counter keeps the current address within each segment during<br />

assembly and provides reference to the current instruction and data.<br />

Text, Data, and Bss Segments<br />

Every program is divided into at most three distinct segments of assembled code and<br />

data: the text segment, the data segment, and the bss segment. Each segment is<br />

reserved for a specific type of storage and receives different treat ment from the<br />

assembler and from the <strong>XENIX</strong> linker when the final program is created.<br />

The text segment is normally reserved for instructions but may also be used for data.<br />

Instructions in this segment are assembled, and the code is copied to the output file.<br />

Data definitions in this segment are also assembled and copied; the code is the value of<br />

the data item. The assembler does not separate the instruction and data code. If the<br />

instructions and data definitions are mixed within the source file, the resulting code is<br />

mixed within the output file.<br />

The data segment is reserved for data. The code is copied to a different part of the<br />

output file and receives different treat ment from the <strong>XENIX</strong> linker.<br />

The bss segment is reserved for uninitialized data only. Instructions or data definitions<br />

with initial values must not be given in this segment. The assembler counts the nu mber<br />

of bytes allocated for this segment and copies this count to the output file. It does not<br />

generate code.<br />

The text segment is implicitly defined at the start of every assembly. Thus, any<br />

instructions or data definitions given when no other segment is explicitly defined are<br />

copied to the text segment. To start a data or bss segment, you must use a .data or .bss<br />

directive. You can explicitly start the text segment with the .text directive (see the<br />

section "Segment Directives," later in this chapter).<br />

Unless otherwise specified, the first statement in the text segment is considered the<br />

program's entry point. In shared-text programs, the instructions and data in the text<br />

segment are write-protected; in nonshared-text programs, they are not. Instructions<br />

and data in the data segment are never write-protected. The bss segment is actually an<br />

extension of the data segment. It begins immediately after the data segment and is<br />

initialized to 0 at the start of program execution.<br />

7-3

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!