5.4 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 and .bits directives place 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. The .bits directive is similar but does not force alignment to a field boundary. See the .field topic and .bits topic.
Figure 5-1 shows how fields are packed into a word. Using the following assembled code, notice that the SPC does not change for the first three fields (the fields are packed into the same word):
1 00000000 60000000 .field 3, 3
2 00000000 64000000 .field 8, 6
3 00000000 64400000 .field 16, 5
4 00000004 01234000 .field 01234h, 20
5 00000008 00001234 .field 01234h, 32
- 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. The .half and .short 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. The .int, .long, and .word 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, .ubyte, .uchar, .uhalf, .uint, .ulong, .ushort, .uword, .string, .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, .char, .short, .int, .long, .float, .double, .word, and .string directives using the following assembled code:
1 00000000 AA .byte 0AAh, 0BBh
00000001 BB
2 00000002 CC .char 0CCh
3 00000004 ABCD .short 0ABCDh
4 00000006 0000DDDD .word 0DDDDh
5 0000000a EEEEFFFF .long 0EEEEFFFFh
6 0000000e 0000DDDD .int 0DDDDh
7 00000012 3FFFFCB9 .float 1.9999
8 00000016 3FFFFFF5 .double 1.99999
0000001a 83A53B8E
9 0000001e 48 .string "Help"
0000001f 65
00000020 6C
00000021 70