These are not instructions but directives: they tell the assembler to place data in the output file. DB stores bytes, DW 16-bit words and DD 32-bit double words. A name in front becomes a label with a type (BYTE, WORD or DWORD), so the assembler knows the size when an instruction uses it. Several values separated by commas are stored one after another; a ? reserves the space without choosing a value.
| Line | Bytes stored |
|---|---|
| B1 DB 5 | 05 |
| S1 DB 'Hi', 13, 10, '$' | 48 69 0D 0A 24 |
| W1 DW 0305h | 05 03 |
| D1 DD 12345678h | 78 56 34 12 |
| P1 DW MSG1 | the offset of MSG1 |
| BUF DB 4 DUP (0) | 00 00 00 00 |
Little-endian
The 8086 stores the low byte of a word first, at the lower address. A DW 0305h is the byte 05h followed by 03h, and a double word is two words, low word first. That is why a far pointer is written as the offset, then the segment.
MOV AL, BYTE PTR [W1] ; first byte of 0305h: 05hADD AL, '0' ; digit -> characterMOV DL, ALMOV AH, 02h ; DOS: print DLINT 21hMOV AL, BYTE PTR [W1+1] ; second byte: 03hADD AL, '0' ; digit -> characterMOV DL, ALMOV AH, 02h ; DOS: print DLINT 21hMOV DX, OFFSET ROW1MOV AH, 09h ; DOS: print the string at DS:DXINT 21hW1 DW 0305hROW1 DB ' ', 5 DUP ('*'), 13, 10, '$'
DUP
count DUP (value) repeats the value count times: BUF DB 80 DUP (?) reserves 80 bytes, ROW DW 10 DUP (0) ten zero words. The value can be a list: DB 3 DUP (1, 2) stores 1 2 1 2 1 2. DUP can also be nested, as in DB 2 DUP (3 DUP (0), 1).
Pitfalls
Data in a .COM sits in the same segment as the code. Put it after the exit, or jump over it; if the CPU runs into it, the bytes are executed as instructions. A label has a size, so MOV AX, B1 on a DB label is a size error; write WORD PTR if you really want two bytes from there. Text of any length belongs in DB; DW and DD accept only a string of a few characters, stored in a byte order that surprises, so keep to numbers and labels there. In a .COM, avoid DD label: it needs a segment value that DOS does not patch in for a .COM.
Later assemblers
MASM also has DQ (8 bytes) and DT (10 bytes) for the 8087, and the synonyms BYTE, WORD and DWORD (N1 WORD 0).