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 IEEE format representation of one or more values and stores them in the current section. The stored value is an IEEE 64-bit double-precision floating-point value, and is stored in two words aligned to a word boundary. (MSP430 has no alignment greater than word alignment.)
- 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 0000 0003 .field 3,3
2 0000 0043 .field 8,6
3 0000 2043 .field 16,5
4 0002 1234 .field 0x1234,16
- The .float directive calculates the IEEE format representation of one or more values and stores them in the current section. The stored value is an IEEE 32-bit single-precision floating-point value, and is stored in one word aligned to a word boundary.
- The .int and .word directives place one or more 16-bit values into consecutive 16-bit values in the current section.
- 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, .word, .int, .long, .ubyte, .uchar, .uhalf, .uint, .ulong, .ushort, .uword, .string, .double, .float, .half, .short, 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, .int, .long, .float, .word, and .string directives using the following assembled code:
1 0000 00AA .byte 0AAh,0BBh
0001 00BB
2 0002 00CC .char 0xCC
3 0004 DDDD .word 0xDDDD
4 0006 FFFF .long 0xEEEEFFFF
0008 EEEE
5 000a DDDD .int 0xDDDD
6 000c FCB9 .float 1.9999
000e 3FFF
7 0010 0048 .string "Help"
0011 0065
0012 006C
0013 0070