AVR Tutorials
The Best AVR Microcontroller Tutorials on the Web

AVR Assembler Directives

Tutorial Objectives


After completing this AVR microcontroller tutorial readers should be able to:
  • Give a definition for the term assembler directive.
  • List the AVR assembler directives.
  • Explain the use of each AVR assembler directives.


AVR Assembler Directives


What is an assembler directive?

Apart from the microcontroller instruction set that is used in writing an AVR assembly code the AVR Assembler support the use of assembler directives. Assembler Directives are used as instruction to the AVR assembler and are in no way translated to machine language during the assembly process.


Assembler Directives are use by the programmer to assist in adjusting the location of the program in memory, defining macros and so fort. A list of the AVR assembler directives available to the AVR assembler is given below.

Some AVR Assembler Directives
Directives Description
BYTE Reserve a Byte for a Variable
CSEG Define the Code Segment Section
DB Define Constant Byte(s)
DEF Define a Symbolic Name
DEVICE Define which Microcontroller to Assemble for
DSEG Define the Data Segment Section
DW Define Constant Word(s)
ENDMACRO Signifies the End of a Macro
EQU Set a Symbol Equal to an Expression
ESEG Define the EEPROM Section
Exit Exit from a File
INCLUDE Read Source Code from a File
LIST Turn List Generation ON
LISTMAC Turn Macro Expression ON
MACRO Signifies the Beginning of a Macro
NOLIST Turn List Generation OFF
ORG Set Program Origin
SET Set Symbol to an Expression


Syntax of AVR Assembler Directives


Each assembler directives in an AVR assembly program must be preceded by a period "." as shown below where the directives INCLUDE and ORG are used.
.include "m8515def.inc"
.org $00
 
begin:     ADD R16, R17      ; Add R17 to R16
           MOV R17, R18      ; Copy R18 to R17


Description of AVR Assembler Directives


Below is an expanded description for a few of the AVR assembler directives listed above. The description for the full compliment of AVR assembler directives is given in the AVR Assembler User Guide.


The INCLUDE Directive - This assembler directive indicate to the assembler to assemble the code contained in the specified file as part of the program. The syntax for this directive is shown below, the file to be included here is m8515def.inc.

.include "m8515def.inc"



The ORG Directive - This assembler directive indicate to the assembler where in the microcontroller memory to start storing the code that follows. The syntax for this directive is shown below, here the location to start storing the machine code for the program is $00. That is, start storing the machine code from address $00 in the program memory.

.org $00


Important Note:
If the ORG directive is written following the CSEG directive, then the machine code that follows is written to SRAM in data memory. This is similar for the ESEG directive and EEPROM memory.

AVR Tutorials hopes this AVR assembly tutorial on AVR assembler directives was beneficial to you and looks forward to your continued visits for all your microcontroller tutorial needs.