SPRUI03E June 2015 – January 2023
Initialize Field
.fieldvalue[, size in bits]
The .field directive initializes a multiple-bit field within a single word (32 bits) of memory. This directive has two operands:
"t.asm", WARNING! at line 1: [W0001] Value truncated to 1
.field 3, 1
Successive .field directives pack values into the specified number of bits starting at the current 32-bit location. Fields are packed starting at the least significant bit (bit 0), moving toward the most significant bit (bit 31) as more fields are added. If the assembler encounters a field size that does not fit in the current 32-bit word, it fills the remaining bits of the current byte with 0s, increments the SPC to the next word boundary, and begins packing fields into the next word.
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 24-bit field. **
3 **********************************************
4 00000000 00BBCCDD .field 0BBCCDDh, 24
5
6 **********************************************
7 ** Initialize a 5-bit field **
8 **********************************************
9 00000000 0ABBCCDD .field 0Ah, 5
10
11 *********************************************
12 ** Initialize a 4-bit field in a new word. **
13 *********************************************
14 00000004 0000000C .field 0Ch, 4
15
16 **********************************************
17 ** Initialize a 3-bit field **
18 **********************************************
19 00000004 0000001C x: .field 01h, 3
20
21 **********************************************
22 ** Initialize a 32-bit relocatable **
23 ** field in the next word **
24 **********************************************
25 00000008 00000004' .field x
Figure 6-6 shows how the directives in this example affect memory.