Designed by Manoj D. Harsule
Lecturer in Electronics &
Communication Dept.
G.H. Raisoni Polytechnic,
Amravati, Maharashtra, India
Microcontroller Basics Directives
System tools
Editor
Construct ALP
Type using Editor
Called as source program
Extension .asm
Assembler
ALP to machine code
Extension .obj or .lst
Linker
Combines more than one
Converts to single
executable
Simulator
Run 8051 program without
using 8051 kit
If not needed use Hex
Converter
Extension must be .hex
Data Types
 Sbit- special function reg.
 Address- 80 H to FF H
 Bit:- addressable RAM
 00 H to 7FH
Byte data type
Addressable byte by byte
No 16 bit word
Directives are commands of
assembly language itself and
have no influence on the
operation of the microcontroller
8051 DIRECTIVES
EQU directive
 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 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 45SPEED SET 46SPEED
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 (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 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(0000 H to FFFF
H).
 Syntax: Name CODE code address
 For example:
 RESET CODE 0 ;Memory location 00h
called “RESET”TABLE CODE 1024
DATA directive
 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 directive
 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 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 (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”
ORG directive : Origin
 The ORG directive is used to specify a
location in program memory where the
program following directive is to be placed.
 Syntax: ORG address
 Address can be given in either in hex or
decimal.
 For example:
 BEGINNING ORG 100 ... ...ORG
1000hTABLE ... ...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.
 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 directive : End of
program
 The END directive is used at the end of
every program. The assembler will stop
compiling once the program encounters
this directive.
 Syntax: END
 For example:
 END ;End of program
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.
 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.

Microcontroller directives

  • 1.
    Designed by ManojD. Harsule Lecturer in Electronics & Communication Dept. G.H. Raisoni Polytechnic, Amravati, Maharashtra, India Microcontroller Basics Directives
  • 2.
  • 3.
    Editor Construct ALP Type usingEditor Called as source program Extension .asm
  • 4.
    Assembler ALP to machinecode Extension .obj or .lst
  • 5.
    Linker Combines more thanone Converts to single executable
  • 6.
    Simulator Run 8051 programwithout using 8051 kit If not needed use Hex Converter Extension must be .hex
  • 7.
    Data Types  Sbit-special function reg.  Address- 80 H to FF H  Bit:- addressable RAM  00 H to 7FH
  • 8.
    Byte data type Addressablebyte by byte No 16 bit word
  • 9.
    Directives are commandsof assembly language itself and have no influence on the operation of the microcontroller 8051 DIRECTIVES
  • 10.
    EQU directive  TheEQU 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.
  • 11.
    SET directive  TheSET 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 45SPEED SET 46SPEED SET 57
  • 12.
    BIT directive  TheBIT 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”
  • 13.
    CODE directive  TheCODE 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
  • 14.
    DATA directive  TheDATA 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”
  • 15.
    IDATA directive  TheIDATA 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”
  • 16.
    XDATA directive  TheXDATA 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”
  • 17.
    ORG directive :Origin  The ORG directive is used to specify a location in program memory where the program following directive is to be placed.  Syntax: ORG address  Address can be given in either in hex or decimal.  For example:  BEGINNING ORG 100 ... ...ORG 1000hTABLE ... ...This program starts at location 100. The table containing data is to be stored at location 1024 (1000h).
  • 18.
    USING directive  TheUSING 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)
  • 19.
    END directive :End of program  The END directive is used at the end of every program. The assembler will stop compiling once the program encounters this directive.  Syntax: END  For example:  END ;End of program
  • 20.
    DB directive  TheDB 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.  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.