4.13 Db Directive

The MPASM DB directive places bytes into program memory.

Suggested Replacement

The PIC Assembler's DB 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 bytes into the current psect. If the operand is a string literal, each character of the string is stored sequentially, with no terminating nul character.

With PIC18 devices, each byte specified will consume one byte of program memory. With Mid-range devices, there will be one byte stored in each program word, with the upper bits of that word left as zeros. To have data encapsulated into retlw instructions, use retlw instructions instead of this directive (see the example in the Dt Directive).

You can use the data psect to hold the values defined. This psect is predefined once you include <xc.inc>. For example:
PSECT data
symbols:
  DB 76h
  DB 'A', -23
  DB "Message",0

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 romData,space=0,class=CONST
symbols:
  DB 76h
  DB 'A', -23
  DB 'Message",0