Tuesday, July 2, 2013


8051 data type and directives



The 8051 micro controller has only one data type. It is 8 bits, and the size of each register is also 8 bits. It is the job of the programmer to break down data larger than 8 bits (00 to FFH, or 0 to 255 in decimal) to be processed by the CPU. For examples of how to process data larger than 8 bits.The data types used by the 8051 can be positive or negative.

DB (define byte) 
  • It 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. 
  • 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 DB examples:
ORG 2000H
DATA1:    DB    28    ;DECIMAL NUMBER 28
DATA2:    DB    1234h    ;HEXADECIMAL
DATA3:    DB    "ABCD"    ;ASCII CHARACTER



Assembler directives
(IT 'S ALSO CALLED PSEUDO CODE)

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. Check your assembler.
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,put constant value will be substituted for the label. 
  • The following uses EQU for the counter constant and then the constant is used to load the R3 register.
CONST    EQU    25H
MOV A,#CONST    ;COPY 25 INTO A


END
  • 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”.

0 comments:

Related Posts Plugin for WordPress, Blogger...
Subscribe to RSS Feed Follow me on Twitter!