You are on page 1of 6

Directives

Unlike instructions being compiled and written to chip program memory, directives are
commands of assembly language itself and have no influence on the operation of the
microcontroller. Some of them are obligatory part of every program while some are used only to
facilitate or speed up the operation.
Directives are written in the column reserved for instructions. There is a rule allowing only one
directive per program line.

EQU directive

The EQU directive is used to replace a number by a symbol. For example:

MAXIMUM EQU 99

After using this directive, every appearance of the label “MAXIMUM” in the program will be
interpreted by the assembler as the number 99 (MAXIMUM = 99). Symbols may be defined this
way only once in the program. The EQU directive is mostly used at the beginning of the program
therefore.

SET directive

The SET directive is also used to replace a number by a symbol. The significant difference
compared to the EQU directive is that the SET directive can be used an unlimited number of
times:

SPEED SET 45
SPEED SET 46
SPEED SET 57

BIT directive

The BIT directive is used to replace a bit address by a symbol. The bit address must be in the
range of 0 to 255. For example:

TRANSMIT BIT PSW.7 ;Transmit bit (the seventh bit in PSW register)
;is assigned the name "TRANSMIT"
OUTPUT BIT 6 ;Bit at address 06 is assigned the name "OUTPUT"
RELAY BIT 81 ;Bit at address 81 (Port 0)is assigned the name ;"RELAY"

CODE directive

The CODE directive is used to assign a symbol to a program memory address. Since the
maximum capacity of program memory is 64K, the address must be in the range of 0 to 65535.
For example:

RESET CODE 0 ;Memory location 00h called "RESET"


TABLE CODE 1024 ;Memory location 1024h called "TABLE"
DATA directive

The DATA directive is used to assign a symbol to an address within internal RAM. The address
must be in the range of 0 to 255. It is possible to change or assign a new name to any register.
For example:

TEMP12 DATA 32 ;Register at address 32 is named ;as "TEMP12"


STATUS_R DATA D0h ;PSW register is assigned the name ;"STATUS_R"

IDATA directive

The IDATA directive is used to change or assign a new name to an indirectly addressed register.
For example:

TEMP22 IDATA 32 ;Register whose address is in register ;at address 32 is named


as "TEMP22"
TEMP33 IDATA T_ADR ;Register whose address is in ;register T_ADR is named as
"TEMP33"

XDATA directive

The XDATA directive is used to assign a name to registers within external (additional) RAM
memory. The addresses of these registers cannot be larger than 65535. For example:

TABLE_1 XDATA 2048 ;Register stored in external


;memory at address 2048 is named
;as "TABLE_1"

ORG directive

The ORG directive is used to specify a location in program memory where the program
following directive is to be placed. For example:

BEGINNING ORG 100


...
...
ORG 1000h
TABLE ...
...

This program starts at location 100. The table containing data is to be stored at location 1024
(1000h).

USING directive

The USING directive is used to define which register bank (registers R0-R7) is to be used in the
program.

USING 0 ;Bank 0 is used (registers R0-R7 at RAM-addresses 0-7)


USING 1 ;Bank 1 is used (registers R0-R7 at RAM-addresses 8-15)
USING 2 ,Bank 2 is used (registers R0-R7 at RAM-addresses 16-23)
USING 3 ;Bank 3 is used (registers R0-R7 at RAM-addresses 24-31)

END directive

The END directive is used at the end of every program. The assembler will stop compiling once
the program encounters this directive. For example:

...
END ;End of program

Directives used for selecting memory segments

There are 5 directives used for selecting one out of five memory segments in the microcontroller:

CSEG ;Indicates that the next segment refers to program memory;

BSEG ;Selects bit-addressable part of RAM;

DSEG ;Indicates that the next segment refers to the part of internal RAM
accessed by
;direct addressing;

ISEG ;Indicates that the next segment refers to the part of internal RAM
accessed by
;indirect addressing using registers R0 and R1); and

XSEG ;Selects external RAM memory.

The CSEG segment is activated by default after enabling the assembler and remains active until
a new directive is specified. Each of these memory segments has its internal address counter
which is cleared every time the assembler is activated. Its value can be changed by specifying
value after the mark AT. It can be a number, an arithmetical operation or a symbol. For example:

DSEG ;Next segment refers to directly accessed registers; and


BSEG AT 32 ;Selects bit-addressable part of memory with address counter
;moved by 32 bit locations relative to the beginning of that
;memory segment.

A dollar symbol "$" denotes current value of address counter in the currently active segment.
The following two examples illustrate how this value can be used practically:

Example 1:

JNB FLEG,$ ;Program will constantly execute this


;instruction (jump instruction),until
;the flag is cleared.

Example 2:
MESSAGE DB ‘ALARM turn off engine’
LENGTH EQU $-MESSAGE-1

These two program lines can be used for computing exact number of characters in the message
“ALARM turn off engine” which is defined at the address assigned the name “MESSAGE”.

DS directive

The DS directive is used to reserve memory space expressed in bytes. It is used if some of the
following segments ISEG, DSEG or XSEG is currently active. For example:

Example 1:

DSEG ;Select directly addressed part of RAM


DS 32 ;Current value of address counter is incremented by 32
SP_BUFF DS 16 ;Reserve space for serial port buffer
;(16 bytes)
IO_BUFF DS 8 ;Reserve space for I/O buffer in size of 8 bytes

Example 2:

ORG 100 ;Start at address 100


DS 8 ;8 bytes are reserved
LAB ......... ;Program proceeds with execution (address of this location is
108)

DBIT directive

The DBIT directive is used to reserve space within bit-addressable part of RAM. The memory
size is expressed in bits. It can be used only if the BSEG segment is active. For example:

BSEG ;Bit-addressable part of RAM is selected


IO_MAP DBIT 32 ;First 32 bits occupy space intended for I/O buffer

DB directive

The DB directive is used for writing specified value into program memory. If several values are
specified, then they are separated by a comma. If ASCII array is specified, it should be enclosed
within single quotation marks. This directive can be used only if the CSEG segment is active.
For example:

CSEG
DB 22,33,’Alarm’,44

If this directive is preceeded by a lable, then the label will point to the first element of the array.
It is the number 22 in this example.

DW directive
The DW directive is similar to the DB directive. It is used for writing a two-byte value into
program memory. The higher byte is written first, then the lower one.

IF, ENDIF and ELSE directives

These directives are used to create so called conditional blocks in the program. Each of these
blocks starts with directive IF and ends with directive ENDIF or ELSE. The statement or symbol
(in parentheses) following the IF directive represents a condition which specifies the part of the
program to be compiled:

 If the statement is correct or if the symbol is equal to one, the program will include all
instructions up to directive ELSE or ENDIF.
 If the statement is not correct or if the symbol value is equal to zero, all instructions are
ignored, i.e. not compiled, and the program continues with instructions following
directives ELSE or ENDIF.

Example 1:

IF (VERSION>3)
LCALL Table_2
LCALL Addition
ENDIF
...

If the program is of later date than version 3 (statement is correct), subroutines “Table 2” and
“Addition” will be executed. If the statement in parentheses is not correct (VERSION<3), two
instructions calling subroutines will not be compiled.

Example 2:

If the value of the symbol called “Model” is equal to one, the first two instructions following
directive IF will be compiled and the program continues with instructions following directive
ENDIF (all instructions between ELSE and ENDIF are ignored). Otherwise, if Model=0,
instructions between IF and ELSE are ignored and the assembler compiles only instructions
following directive ELSE.

IF (Model)
MOV R0,#BUFFER
MOV A,@R0
ELSE
MOV R0,#EXT_BUFFER
MOVX A,@R0
ENDIF
...

Control directives
Control directives start with a dollar symbol $. They are used to determine which files are to be
used by the assembler during compilation, where the executable file is to be stored as well as the
final layout of the compiled program called Listing. There are many control directives, but only
few of them is of importance:

\$INCLUDE directive

This directive enables the assembler to use data stored in other files during compilation. For
example:

\$INCLUDE(TABLE.ASM)

You might also like