Assembler Directives in 8051 Microcontroller

Various assembler directives in 8051 microcontrollers are used during assembly language programming. 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.

Microcontroller 8051 Directives

Following Assembler Directives are used in 8051 microcontroller.

ORG (Origin)

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

Syntax: ORG ROM-address

Address can be given in either in hex or decimal.

For example:

ORG 100

ORG 1000h

TABLE …

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

EQU

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

Syntax: Name EQU Constant

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

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.

Syntax: Name SET Constant

SPEED SET 45

SPEED SET 46

SPEED SET 57

BIT

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 (00 H to FF H).

Syntax: Name BIT 8051-bit

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

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(0000 H to FFFF H).

Syntax: Name CODE code-address

For example:

RESET CODE 0 ; Memory location 00h called “RESET”.

TABLE CODE 1024 ; Memory location 1024h called “TABLE”.


DATA

The DATA directive is used to assign a symbol to an address within internal RAM and SFR. The address must be in the range of 0 to 255 (00 H to FF H). It is possible to change or assign a new name to any register.

Syntax: Name DATA data-address

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

The IDATA directive is used to change or assign a new name to an indirectly addressed register. It is an address of entire internal RAM.

Syntax: Name IDATA idata-address

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

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 (0000 h to FFFF h).

Syntax: Name XDATA xdata-address

For example:

TABLE_1 XDATA 2048 ; Register stored in external; memory at address 2048 is named; as “TABLE_1”.


USING

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

Syntax: USING Bank-no.

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

The END directive is used at the end of every program. It indicates the end of program. The assembler will stop compiling once the program encounters this directive.

Syntax: END

For example:

END ; End of program


DB (Define Byte)

The DB directive is used for writing specified value into program memory. If several values are specified, then they are separated by a comma. Here data can be in decimal, binary, hex or ASCII formats.

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.

DB directive is the only directive that can be used to define ASCII strings larger than two characters; therefore, it should be used for all ASCII data definitions.

For example:

NUM1 DB 22,33, ‘Alarm’, 44

String_U DB ‘DBATU’

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

Recent posts

Leave a Comment

Your email address will not be published. Required fields are marked *