Escolar Documentos
Profissional Documentos
Cultura Documentos
An assembler is a program that translates symbolic code (assembly language) into executable
object code. This object code can be executed with a 80C51-compatible microcontroller. If
you have ever written a computer program directly in machine-recognizable form, such as
binary or hexadecimal code, you will appreciate the advantages of programming in symbolic
assembly language.
Assembly language operation codes (mnemonics) are easily remembered (MOV for move
instructions, ADD for addition, and so on). You can also symbolically express addresses and
values referenced in the operand field of instructions. Because you assign these names, you
can make them as meaningful as the mnemonics for the instructions. For example, if your
program must manipulate a date as data, you can assign it the symbolic name DATE. If your
program contains a set of instructions used as a timing loop (executed repeatedly until a
specific amount of time has passed), you can name the instruction group TIMER_LOOP.
An assembly program has three parts:
Machine instructions - Code the machine can execute. Detailed discussion of the
machine instructions is in the hardware manuals of the 80C51 microcontroller.
Assembler directives - Define the program structure and symbols, and generate non
executable code (data, messages, and so on.).
Assembler controls - Set assembly modes and direct assembly flow.
Cx51
Page | 1
Since the Cx51 Compiler is a cross compiler, some aspects of the C programming language
and standard libraries are altered or enhanced to address the peculiarities of an embedded
target processor.
OHX51
The OHX51 Object-HEX Converter creates an Intel HEX file from an absolute object file
that is generated by the LX51 and BL51 Linkers. Program code that is stored in the absolute
object file is converted into hexadecimal values and is then stored in an Intel HEX formatted
file. An EPROM programmer or emulator may then use the Intel HEX file to program a
device.
Data Types in Cx51
The Cx51 Compiler provides several basic data types you may use in your C programs. The
compiler supports the standard C data types as well as several data types that are unique to
the Cx51 platform.
Data Types
bit
signed char
unsigned char
enum
signed short int
unsigned short int
signed int
unsigned int
signed long int
unsigned long int
float
double
sbit
sfr
sfr16
Bits
1
8
8
8 / 16
16
16
16
16
32
32
32
32
1
8
16
Bytes
1
1
1 or 2
2
2
2
2
4
4
4
4
1
2
Value Range
0 to 1
-128 +127
0 255
-128 +127 or -32768 +32767
-32768 +32767
0 65535
-32768 +32767
0 65535
-2147483648 +2147483647
0 4294967295
1.175494E-38 3.402823E+38
1.175494E-38 3.402823E+38
0 or 1
0 255
0 65535
The Cx51 Compiler provides access to all 8051 memory areas. Variables may be explicitly
assigned to a specific memory space (by including a memory type specifier in the
declaration) or implicitly assigned (based on the memory model).
Memory
Type
code
data
idata
bdata
Description
Program memory (64 KBytes); accessed by opcode MOVC @A+DPTR.
Directly addressable internal data memory; fastest access to variables (128
bytes).
Indirectly addressable internal data memory; accessed across the full
internal address space (256 bytes).
Bit-addressable internal data memory; supports mixed bit and byte access
Page | 2
xdata
far
pdata
(16 bytes).
External data memory (64 KBytes); accessed by opcode MOVX @DPTR.
Extended RAM and ROM memory spaces (up to 16MB); accessed by user
defined routines or specific chip extensions (Philips 80C51MX, Dallas
390).
Paged (256 bytes) external data memory; accessed by opcode MOVX
@Rn.
IN C
1. #include
The #include directive causes the C pre-processor to include the contents of the specified file
in the compilation before continuing with the rest of the current file. The #include directive
may be used to specify two different types of header (or include) files: system header files
and user header files.
System header files are included as follows:
#include <filename>
These include files are installed in the \INC\ folder. They are a part of the Keil development
tools release and should not be modified. When a system header file is specified, the compiler
searches for the file in the following folders in order:
Note
a. Include files usually have an extension of .H indicating they are Header files. We
recommend you use this standard for your user header files.
b. Typically, include files contain only variable declarations (not definitions), macro
definitions, and definitions for Special Function Registers.
c. Include files may contain variable definitions. However, you must make certain that
such a header file is only included in one C file in your project. Otherwise, multiple
variables with the same name may be defined resulting in linker errors.
Page | 3
The #if directive tests an expression and if the result is true (non-zero) allows the compiler to
process subsequent text (until the next #else, #elif, or #endif directive). If the result is false
(zero), subsequent text is not processed by the compiler.
#if expression
.
.
.
#endif
IN ASSEMBLY
4. SEGMENT Assembler Statement
Description :
The SEGMENT statement declares a generic segment along with memory class and
segment location options.
Where
i.
segname specifies the symbol name to assign to the segment. This symbol is
references by subsequent RSEG statements. It may also be used in expressions to
represent the base or starting address of the combined segment.
ii.
class is the memory classification for the segment. The class specifies the memory
space where the segment is located.
iii.
relocation determines what relocation options are available to the linker for this
segment.
Page | 4
iv.
alignment determines what address alignment options are available to the linker for
this segment.
The name of each segment in a source module must be unique. The linker combines
segments that have the same type.
5. RSEG Assembler Statement
Description:
The RSEG statement selects a relocatable segment that was previously declared using the
SEGMENT statement.
Example
MYPROG
SEGMENT CODE
RSEG
MYPROG
6. IF Assembler Statement
Syntax:
Description:
IF expression
Example:
Page | 5
IF (SWITCH = 1)
.
ELSEIF (SWITCH = 2)
.
ELSE
.
ENDIF
7. IF Assembler Directive
Arguments: IF expression
Description:
Example
$IF (SWITCH = 1)
$ELSEIF (SWITCH = 2)
Page | 6
$ELSE
$ENDIF
8. SET Assembler Directive
Arguments:
Description:
The SET directive assigns numeric values (number) to the specified symbols. Any symbols
that do not include an explicit number assignment are assigned the value 0FFFFh. The
symbols defined with SET may be used only with the IF and ELSEIF conditional assembly
directives. They may not be used directly in assembly instructions.
Note
a. Symbols defined with the SET directive may be used only with the IF and ELSEIF
directives. They may not be used with the IF and ELSEIF statements.
Example
A51 SAMPLE.ASM
Page | 7