All programs require data:
- small constants like 1, can usually be embedded within machine code instructions that use them
- large constants sometimes don't fit the machine code form so go into data and are referenced by the code
- programs often use string literals for file & path names, prompts, etc..
- storage buffers as space to read user input or from a file
- global variables, initialized to zero or other
- floating point constants go in memory as they are usually to large to fit as an immediate within a machine code instruction.
As mentioned above, in some cases the data can be embedded within machine code instructions, as what are called immediates, a short term for an immediate addressing mode. But in many other cases, constants are done as data that is referenced by the machine code rather than embedded within the machine code — the address of the data is embedded within the machine code (using some addressing mode).
In short, we need to be able to declare data in assembly language just like we need to be able to declare data in all other languages. There must also then be a way for program files to capture that code and its data.
If you label the data then you can use (make a reference to) that label from within your code & data.
Most assemblers will also have a notion of separate code & data sections. A .data
directive (or whichever is appropriate for this assembler) will tell the assembler to collect subsequent data declarations together into the data section of the assembler & linker output. Usually in the assembly source code, we can switch back and forth between code and data sections, so as to keep data related to code nearby in the source, but possibly collected separately in the constructed program file according to the way program files are defined.