Uninitialised Data

Sometimes we want to set aside some data without actually initialising it to any particular values. Here are some examples of doing this.

myval      DB ?
thisval    DD ?
array1     RB 32
array2     RW 1000

The first two lines declare a byte and a double word respectively, without initialising them to anything.

The second last line reserves 32 bytes of space, but doesn't set them to anything. The final line sets aside 1000 words of data without initialising them.

Note that for large arrays it is best to reserve space for them and not initialise them in the data definition, but to write a routine in code that actually initialises the values in the array (if necessary). This can make your program smaller since the initialisation is done by a small piece of code instead of a long set of explicit values contained within your program.

Since initialised and uninitialised data are treated differently, it is sensible to separate the two into different sections. Of course sometimes you want certain pieces of data to occur in a given order, in which case this can't be done, but otherwise, separating the two different kinds of data out gives the assembler a chance to make use of the distinction.

Although not required, one can place .data before the data declarations in a program, just as we put .code before the code.