4.9.9 Db Directive
The DB
directive is used to initialize bytes of program
memory.
The directive takes a comma-separated list of arguments. Each argument can be a numeric
value (e.g., 55
), a character constant (e.g. 'T'
), or a
string (e.g. "level"
or 'level'
). Each argument or each
character of a string argument is written as one byte into consecutive program memory
locations within the current psect.
The encoding of the values written depend on the delta
flag of the psect that contains the directive. In the following code:
PSECT myBytes,class=CODE,delta=2
alabel:
DB ’X’,1,2,3,4,
the size of the address unit in the program memory specified by the
delta
psect flag (see 4.9.47.4 Delta Flag) is 2 bytes (true for Baseline and
Mid-range PIC devices). In this case, the DB
directive will initialize
each word of program memory with the upper byte set to zero, specifically (in
hexadecimal):
0058 0001 0002 0003 0004
delta
flag set to 1, no padding will occur. For the
code:PSECT myBytes,class=CODE,delta=1
alabel:
DB 'X',1,2,3,4
the
following (hexadecimal) data will be defined in the HEX file for the program memory.58 01 02 03 04
DB
directive, for
example:PSECT myConst,class=CODE,delta=1
bytes:
DB "a terminated string",0
will
define:61 20 74 65 72 6D 69 6E 61 74 65 64 20 73 74 72 69 6E 67 00
The DB
directive cannot be used to created objects in data memory. For
that, use the DS
directive (see 4.9.13 Ds Directive).