Directives That Define Sections

Five directives associate the various portions of an assembly language program with the appropriate sections:

The .data directive identifies portions of code to be placed in data memory.

Data memory usually contains initialized data.

The .ds directive functions like .data; however, with .ds you can specify an optional address to initialize a new data address.

The .entry directive identifies the starting address of the program counter.

The current address is used by default, but you can specify an optional ad-dress.

The .ps directive identifies portions of code to be placed in program memory. With .ps you can specify an additional address to initialize a new program address.

The .text directive identifies portions of code in the .text section. The .text section usually contains executable code.

Example 5–1 shows how you can use sections directives to associate code and

data with the proper sections. This is an output listing; column 1 shows line num-bers, and column 2 shows the section program counter (SPC) values. (Each section has its own section program counter, or SPC. When code is first placed in a section, its SPC equals 0. When you resume assembling into a section, its SPC resumes counting as if there had been no intervening code.

After the code in Example 5–1 is assembled, the sections contain:

.text Initialized bytes with the values 1, 2, 3, 4, 5, and 6

.data Initialized bytes with the values 9, 10, 11, and 12

Directives That Reference Other Files

The .copy and .include directives tell the assembler to read source statements from another file. This is the syntax for these directives:

.copy ”filename”

.include ”filename”

The .copy and .include directives tell the assembler to begin reading source statements from another file. When the assembler finishes reading the source statements in the copy/include file, it resumes reading source statements from the current file. The statements read from the copied or included files are printed in the listing file.

The filename names a copy/include file that the assembler reads statements from. The filename can be a complete pathname, a partial pathname, or a file-name with no path information. The assembler searches for the file in the directory that contains the current source file. The current source file is the file being assembled when the .copy or .include directive is encountered.

Assembler Directives

Directives that Enable Conditional Assembly

The .if/.else/.endif directives tell the assembler to conditionally assemble a block of code according to the evaluation of an expression. Note that you cannot nest .if statements.

The .if expression directive marks the beginning of a conditional block and assembles code if the .if condition is true (not zero).

The .else directive marks a block of code to be assembled if .if is false.

The .endif directive marks the end of a conditional block and terminates the block. The expression parameter can be either a numeric value or a previously defined symbol.

Directives That Initialize Memory

Each of these directives, with the exception of the .byte and .string directives,

aligns the object to a 16-bit word boundary.

The .byte directive places one or more 8-bit values into consecutive words of the current section.

The .word directive places one or more 16-bit values into consecutive words in the current section.

The .string directive places 8-bit characters from one or more character strings into the current section.

The .long directive places one or more 32-bit values into consecutive 32-bit fields in the current section.

The .int directive places one or more 16-bit values into consecutive words in the current section.

The .qxx directive places one or more 16-bit, signed 2s-complement values

into consecutive words in the current section. Note that the decimal point is displaced xx places from the LSB.

The .lqxx directive places one or more 32-bit, signed 2s-complement values into consecutive 32-bit fields in the current section. Note that the decimal point is displaced xx places from the LSB.

The .float directive calculates 32-bit IEEE floating-point representations of single precision floating-point value and stores it in two consecutive words in the current section.

The .bfloat directive calculates a 16-bit, signed 2s-complement exponentand a 32-bit, signed 2s-complement mantissa.

The .efloat directive calculates a 16-bit, signed 2s-complement exponent and a 16-bit, signed 2s-complement mantissa.

The .tfloat directive calculates a 32-bit, signed 2s-complement exponent and a 64-bit, signed 2s-complement mantissa.

The .double directive calculates a 64-bit IEEE floating-point representation of a double precision floating-point value and stores it in four consecutive words in the current section.

The .space directive reserves a specified number of bits in the current section. The assembler advances the SPC and skips the reserved words.

When you use a label with .space, it points to the first word of the reserved block.

Miscellaneous Directives

This section discusses miscellaneous directives.

The .end directive terminates assembly. It should be the last source statement of a program. This directive has the same effect as an end-of-file character.

The .listoff directive overrides the –l option and prohibits source listing.

The .liston directive begins source listing.

The .mmregs directive defines symbolic names for the memory-mapped register. Using .mmregs is the same as executing a .set for all memory-mapped registers—for example, greg .set 4—and makes it unnecessary to define these symbols. See Table 5–2, page 5-25, for a list of memory-mapped registers.

The .set directive equates meaningful symbol names to constant values or strings. The symbol is stored in the symbol table and cannot be redefined; for example:

bval .set 0100h

.byte bval

B bval

.byte/.string Directives Reference

Syntax .byte value 1 [, ... , value n ]

.string string 1 [, ... , string n ]

Description The .byte and .string directives place one or more 8-bit values into consecutive bytes of the current section. A value or a string can be either:

An expression that the assembler evaluates and treats as an 8-bit signed number, or

A character string enclosed in double quotes. Each character in a string represents a separate value.

The .byte directive places one or more 8-bit values into consecutive words of the current section.

Unlike the .byte directive, the .string directive places the 8-bit values into memory in a packed form in the order they are encountered. If a word is not filled, the remaining bits are filled with zeros.