4.18 Dw Directive

The MPASM DW directive places words into program memory.

Suggested Replacement

The PIC Assembler's DW directive inside a suitable psect performs a similar function, but there are some differences in its operation.

This directive places the value of its comma-separated operands as 16-bit words into the current psect. For PIC18 devices, each operand will consume two addresses (bytes). For other devices, the assembler will attempt to place the entire operand value into one program memory word, but since program memory locations of these devices are less than 2 bytes wide, the value may be truncated. Typically, data is stored in the program memory of these devices using retlw instructions that store each byte in separate memory locations.

If the operand is a string literal, each character of the string is stored sequentially as a 16-bit word, with no terminating nul character.

You can use the data psect to hold the values defined. This psect is predefined once you include <xc.inc>. For example:

PSECT data
modifiers:
  DW 1354h
  DW 's', -23
  DW 'Mode'
Alternatively, you can define your own psect and allocate it to program memory. Ensure that the psect's space flag is set to 0 (the default value). It can be assigned an address by associating it with a suitable linker class (e.g. CONST for PIC18 devices, or STRCODE for other devices), or by explicitly positioning the psect using the linker's -P option (accessible from the driver using the -Wl option), as in the following PIC18 example.
PSECT myData,space=0,class=CONST
modifiers:
  DW 1354h
  DW 's', -23
  DW 'Mode'