Site Search

Search

SECTION V - 8051 DATA TYPES AND DIRECTIVES

SECTION - V - 8051 DATA TYPES AND DIRECTIVES:

Microcontroller 8051 has only one 8-bits data type and the size of each register is also 8 bits. The job of the programmer is to break down data larger than 8 bits [00 to FFH, or 0 to 255 in decimal] to be processed by the CPU. The data type used by the 8051 can be positive or negative.

DB [Define Byte]:

The DB directive is used to define the 8-bit data and 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] is required. The assembler will convert the numbers in hex. To indicate ASCII, simply put it 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. It should be used for all ASCII data definitions.

ORG 300H

DATA1: DB 30 ;Decimal number [1E in HEX]

DATA2: DB 01010101B ;Binary [55 in HEX]

DATA3: DB 40H ; HEX number

ORG 500H

DATA4: DB "2482" ;ASCII Numbers

DATA5: DB "My name is Ayesha Imtiaz" ;ASCII Characters

Either single or double quotes can be used around ASCII strings. Can be useful for strings, which contain a single quote such as "O'Really". DB is also used to allocate memory in byte-sized chunks.

Assembler Directives:

The following Assembler directives are widely used in 8051 Assembly language programming.

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 into hex. Some assemblers use ".ORG" [notice the dot] instead of "ORG" for the origin directive. For tha you need to check your assembler.

EQU [Equate]:

EQU 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. Here uses EQU for the counter constant ans then the constant is used to load the R4 register.

COUNT EQU 22

.... ....

MOV R4,#COUNT

After executing the instruction "MOV R4,#COUNT", the register R4 will be loaded with the value 22 [# sign indicates it is a value, notice it].

What is the advantage of using EQU?

The answer is that, lets say in a program there is a constant value [a fixed value] used in many different places in the program, and the programmer wants to change its value through out the entire program. By the use of EQU, a programmer can change all valves at once and the assembler will change all of it occurrences, rather than search the entire program and to change the value one by one to fine every occurrence, just change the constant value followed by EQU results changing the all occurrences at once.

END Directive:

END directive pseudocode is very important. END indicates to the assemblere the end of the source [asm ] file. The END directive is the last line of an 8051 program. In assembly language programming anything after the END directive is ignored by the assembler. Some assembler uses ".END" [notice the dot] instead of "END"

Labels in Assembly Language Programming and its Rules:

Programmer can make a program easier to read and maintain by choosing label names that are meaningful. There are several rules that names must follow. First, each label name must be unique. The names used for labels in assembly language programming consists of alphabetic letters in both upper and lower case, the digits 0 through 9, and the special characters question mark [?], period [.], at [@], underline [_], and dollar sign [$]. The first character of the label must be an alphabetic character, it cannot be a number. Every assembler has some reserved words which must not be used as labels in the program. These reserve words are the mnemonics for the instructions e.g. like "MOV", "DJNZ", "MUL" and "ADD" are reserved as these are the instruction mnemonics.