5.3 Directives that Initialize Values
Several directives assemble values for the current section. For example:
- The .byte and .char directives place one or more 8-bit values into consecutive bytes of the current section. These directives are similar to .word, .int, and .long, except that the width of each value is restricted to 8 bits.
- The .double directive calculates the double-precision (64-bit) IEEE floating-point representation of one or more floating-point values and stores them in two consecutive words in the current section. The .double directive automatically aligns to the double-word boundary.
- The .field directive places a single value into a specified number of bits in the current word. With .field, you can pack multiple fields into a single word; the assembler does not increment the SPC until a word is filled. If a field will not fit in the space remaining in the current word, .field will insert zeros to fill the current word and then place the field in the next word. See the .field topic.
Figure 5-1 shows how fields are packed into a word. Using the following assembled code, notice that the SPC does not change (the fields are packed into the same word):
1 00000000 00000003 .field 3,4
2 00000000 00000083 .field 8,5
3 00000000 00002083 .field 16,7
- The .float directive calculates the single-precision (32-bit) IEEE floating-point representation of a single floating-point value and stores it in a word in the current section that is aligned to a word boundary.
- The .half and .short directives place one or more 16-bit values into consecutive 16-bit fields (halfwords) in the current section. These directives automatically align to a short (2-byte) boundary.
- The .int, .long, and .word directives place one or more 32-bit values into consecutive 32-bit fields (words) in the current section. These directives automatically align to a word boundary.
- The .stringand .cstring directives place 8-bit characters from one or more character strings into the current section. The .string and .cstring directives are similar to .byte, placing an 8-bit character in each consecutive byte of the current section. The .cstring directive adds a NUL character needed by C; the .string directive does not add a NUL character.
- The .ubyte, .uchar, .uhalf, .uint, .ulong, .ushort, and .uword directives are provided as unsigned versions of their respective signed directives. These directives are used primarily by the C/C++ compiler to support unsigned types in C/C++.
NOTE
Directives that Initialize Constants When Used in a .struct/.endstruct Sequence
The .bits, .byte, .char, .int, .long, .word, .double, .half, .short, .string, .ubyte, .uchar, .uhalf, .uint, .ulong, .ushort, .uword, .float, and .field directives do not initialize memory when they are part of a .struct/ .endstruct sequence; rather, they define a member’s size. For more information, see the .struct/.endstruct directives.
Figure 5-2 compares the .byte, .half, .word, and .string directives using the following assembled code:
1 00000000 000000AB .byte 0ABh
2 .align 4
3 00000004 0000CDEF .half 0CDEFh
4 00000008 89ABCDEF .word 089ABCDEFh
5 0000000c 00000068 .string "help"
0000000d 00000065
0000000e 0000006C
0000000f 00000070