0% found this document useful (0 votes)
78 views3 pages

Data Types and Derivatives

Uploaded by

Varada I B
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
78 views3 pages

Data Types and Derivatives

Uploaded by

Varada I B
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

8051 data type and directives

The 8051 microcontroller has only one data type. It is 8 bits, and the size of each register is also 8 bits.
The programmer has to break down data larger than 8 bits (00 to FFH, or 0 to 255 in decimal) so that it
can be processed by the CPU.

Assembling and Running an 8051 Assembly Language Program

The steps to create, assemble, and run an assembly language program are as follows
• First, an editor is used to type in a program. The Editor must be able to produce an ASCII file.
The file is saved with "asm" extension and this source file is used by the assembler.
• The ".asm" source file contains the program code created in Step 1. It is fed to an 8051
assembler. The assembler then converts the assembly language instructions into machine code
instructions and produces a .obj file (object file) and a .lst file (list file). It is also called as
a source file.
• Assemblers require a third step called linking. The link program takes one or more object files
and produces an absolute object file with the extension ".abs".
• Next, the ".abs" file is fed to a program called "OH" (object to hex converter), which creates a
file with the extension ".hex" that is ready to burn in to the ROM.

TRACE KTU

8051 Directives
An assembly language program is a series of statements, which are either assembly language
instructions such as ADD and MOV, or statements called directives.
An instruction tells the CPU what to do, while a directive (also called pseudo-instructions) gives
instructions to the assembler. That means, directives do not generate machine code and are used only
by the assembler, whereas instructions are translated into machine code for the CPU to execute.
For example, ADD and MOV instructions are commands which the CPU runs, while ORG and END
are assembler directives. The assembler places the opcode to the memory location 0 when the ORG
directive is used, while END indicates to the end of the source code.
Assembler directives

The following are some more widely used directives of the 8051.

DB (define byte)

The DB directive is used to define the 8-bit data. When DB is used to define data, the numbers can be
in decimal, binary, hex, or ASCII formats. For decimal, the “D” after the decimal number is optional,
but using “B” (binary) and “H” (hexadecimal) for the others is required. Regardless of which is used,
the assembler will convert the numbers into hex. To indicate ASCII, simply place the characters in
quotation marks (‘like this’). The assembler will assign the ASCII code for the numbers or characters
automatically. The 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. Following are some
examples of DB directives:

TRACE KTU
Either single or double quotes can be used around ASCII strings. This can be useful for strings, which
contain a single quote such as “O’Leary”. DB is also used to allocate memory in byte-sized chunks.

ORG (origin)

The ORG directive is used to indicate the beginning of the address. The number that comes after ORG
can be either in hex or in decimal. If the number is not followed by H, it is decimal and the assembler
will convert it to hex. Some assemblers use “. ORG” (notice the dot) instead of “ORG” for the origin
directive.

EQU (equate)

This is used to define a constant without occupying a memory location. The EQU directive does not set
aside storage for a data item but associates a constant value with a data label so that when the label
appears in the program, its constant value will be substituted for the label. The following uses EQU for
the count constant and then the constant is used to load the R3 register.

When executing the instruction “MOV R3, ttCOUNT”, the register R3 will be loaded with the value 25
(notice the # sign).
What is the advantage of using EQU? Assume that there is a constant (a fixed value) used in many
different places in the program, and the programmer wants to change its value throughout. By the use
of EQU, the programmer can change it once and the assembler will change all of its occurrences, rather
than search the entire program trying to find every occurrence.
END directive

Another important pseudocode is the END directive. This indicates to the assembler the end of the
source (.asm) file. The END directive is the last line of an 8051 program, meaning that in the source
code anything after the END directive is ignored by the assembler. Some assemblers use “. END”
(notice the dot) instead of “END”.

Rules for labels in Assembly language

By choosing label names that are meaningful, a programmer can make a program much easier to read
and maintain. There are several rules that these names must follow.
• Each label name must be unique. The names used for labels in assembly language
programming consist of alphabetic letters in both uppercase and lowercase, number 0 through
9, and special characters such as question mark (?), period (.), at the rate @, underscore (_),
and dollar ($).
• The first character should be an alphabetical character; it cannot be a number.
• Reserved words cannot be used as a label in the program. For example, ADD and MOV words
are the reserved words, since they are instruction mnemonics.

TRACE KTU

You might also like