Professional Documents
Culture Documents
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
preceded by a label, then the label will
point to the first element of the array.
It is the number 22 in this example.
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
TRANSMITOUTPUT BIT 6 ;Bit at address 06 is assigned
the name OUTPUTRELAY 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
RESETTABLE CODE 1024 ;Memory location
1024h called TABLE
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
TEMP12STATUS_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 TEMP22TEMP33
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
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 RAMaddresses 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)
DATATYPE
PRIMARY
DATATYPE
DERIVED
DATATYPE
INTEGER
CHAR
FLOAT
VOID
ARRAY
POINTER
STRUCTURE
UNION
USER DEFINED
TYPE
TYPEDEF
ENUM
Keyword
Format
Specifier
Size
Data Range
char
%c
1 Byte
-128 to +127
unsigned char
%c
1 Bytes
0 to 255
int
%d
2 Bytes
-32768 to
+32767
long int
%ld
4 Bytes
-231 to +231
unsigned int
%u
2 Bytes
0 to 65535
4 Bytes
-3.4e38 to
+3.4e38
8 Bytes
-1.7e38 to
+1.7e38
10Bytes
-3.4e38 to
+3.4e38
float
double
long double
%f
%lf
%Lf
Example
Syntax:
typedef <type> <identifier>;
typedef int
marks;
marks batch1,batch2;