Skip to main content
Engineering LibreTexts

2.3: Assembler Directives

  • Page ID
  • \( \newcommand{\vecs}[1]{\overset { \scriptstyle \rightharpoonup} {\mathbf{#1}} } \) \( \newcommand{\vecd}[1]{\overset{-\!-\!\rightharpoonup}{\vphantom{a}\smash {#1}}} \)\(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\) \(\newcommand{\id}{\mathrm{id}}\) \( \newcommand{\Span}{\mathrm{span}}\) \( \newcommand{\kernel}{\mathrm{null}\,}\) \( \newcommand{\range}{\mathrm{range}\,}\) \( \newcommand{\RealPart}{\mathrm{Re}}\) \( \newcommand{\ImaginaryPart}{\mathrm{Im}}\) \( \newcommand{\Argument}{\mathrm{Arg}}\) \( \newcommand{\norm}[1]{\| #1 \|}\) \( \newcommand{\inner}[2]{\langle #1, #2 \rangle}\) \( \newcommand{\Span}{\mathrm{span}}\)\(\newcommand{\AA}{\unicode[.8,0]{x212B}}\)

    Assembler directives are directions to the assembler to take some action or change a setting. Assembler directives do not represent instructions, and are not translated into machine code.

    For this assembler, all directives begin with a “.” or “#” (the comment is a #), and the directive must exist on a separate line from any other assembler directive or assembler instruction. There are 4 assembler directives and the comment tag.

    • .text – The .text directive tells the assembler that the information that follows is program text (assembly instructions), and the translated machine code is to be written to the text segment of memory.
    • .data – The .data directive tells the assembler that information that follows is program data. The information following a .data instruction will be data values, and will be stored in the data segment.
    • .label – A label is an address in memory corresponding to either an instruction or data value. It is just a convenience so the programmer can reference an address by a name. It will be used as follow:

      .label name

      The label is a tag that can be referenced in place of an address in any assembly instruction that can take a label/adress. Labels and addresses can be used interchangeably.

    • .number – The number directive tells the assembler to set aside 2 bytes of memory for a data value, and to initialize the memory to the given value. It will often be used with the .label directive to set a label to a 2-byte memory value, and initialize the value, as shown in the following code fragment.
      .label var1
          .number 5

      This statement allocates space for the variable var1, and assigns that space in memory the value 5. The data for this CPU will only work with 2-byte (16-bit) integer numbers so discrete values from -32768..32767 (inclusive) can be used. All data values are in decimal; the assembler will not recognize hex values.

    • # - the # (hashtag) is used to specify a comment. Anything on a line which begins with a “#” is a comment line and ignored by the assembler.

    This page titled 2.3: Assembler Directives is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by Charles W. Kann III via source content that was edited to the style and standards of the LibreTexts platform; a detailed edit history is available upon request.

    • Was this article helpful?