SLAU131Y October 2004 – June 2021
Initialize Field
.fieldvalue[, size in bits]
The .field directive initializes a multiple-bit field within a single word (16 bits) of memory. This directive has two operands:
*** WARNING! line 21: W0001: Field value truncated to 1
.field 3, 1
Successive .field directives pack values into the specified number of bits.
The .field directive is similar to the .bits directive (see the .bits topic). However, the .bits directive does not force alignment to a field boundary and does not automatically increment the SPC when a word boundary is reached.
Use the .align directive to force the next .field directive to begin packing a new word.
If you use a label, it points to the byte that contains the specified field.
When you use .field in a .struct/.endstruct sequence, .field defines a member's size; it does not initialize memory. For more information, see the .struct/.endstruct/.tag topic.
This example shows how fields are packed into a word. The SPC does not change until a word is filled and the next word is begun.
1 ************************************
2 ** Initialize a 14-bit field. **
3 ************************************
4 0000 0ABC .field 0ABCh, 14
5
6 ************************************
7 ** Initialize a 5-bit field **
8 ** in the same word. **
9 ************************************
10 0002 000A L_F: .field 0Ah, 5
11
12 ************************************
13 ** Write out the word. **
14 ************************************
15 .align 4
16
17 *******************************************************
18 ** Initialize a 4-bit field. Field starts a new word **
19 *******************************************************
20 0004 000C x: .field 0Ch, 4
21
22 *******************************************************
23 ** 16-bit relocatable field in the next word **
24 *******************************************************
25 0006 0004! .field x
26
27 ************************************
28 ** Initialize a 16-bit field. **
29 ************************************
30 0008 4321 .field 04321h, 16
Figure 6-7 shows how the directives in this example affect memory.