Você está na página 1de 7

Ax51

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

The C programming language is a general-purpose programming language that provides code


efficiency, elements of structured programming, and a rich set of operators. C is not a big
language and is not designed for any one particular area of application. Its generality
combined with its absence of restrictions, makes C a convenient and effective programming
solution for a wide variety of software tasks. Many applications can be solved more easily
and efficiently with C than with other more specialized languages.
The Cx51 Optimizing C Compiler is a complete implementation of the American National
Standards Institute (ANSI) standard for the C language. The Cx51 Compiler is not a universal
C compiler adapted for the 8051 target. It is a ground-up implementation, dedicated to
generating extremely fast and compact code for the 8051 microprocessor. The Cx51 Compiler
provides you with the flexibility of programming in C and the code efficiency and speed of
assembly language.
The C language on its own is not capable of performing operations (such as input and output)
that would normally require intervention from the operating system. Instead, these
capabilities are provided as part of the standard library. Because these functions are separate
from the language itself, C is especially suited for producing code that is portable across a
wide number of platforms.

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

Memory Types in Cx51

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:

Paths specified by the INCDIR directive.


Paths specified by the C51INC environment variable.

User header files are included as follows:


#include "filename"
These include files are user-created and may reside anywhere on your computer. When a user
header file is specified, the compiler searches for the file in the following folders in order:

The current folder.


The source file folder.
Paths specified by the INCDIR directive.
Paths specified by the C51INC environment variable.

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

d. It is possible to begin or end a function in an include file. It is also possible to put


function and variable definitions in include files. While these kinds of things are
possible, they are very confusing and are not good coding habits to get into.
Therefore, we do not recommend that you do them.
2. #define

The #define directive defines a pre-processor macro.


#define macro-name (arg , arg ... ) replacement-text
You may use #define to create function-like macros with or without arguments. Macros are
syntactically similar to function calls. When a defined macro is encountered in the source file,
the macro-name and any arguments are replaced by the replacement-text.
3. #if

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

Syntax: segname SEGMENT class relocation alignment

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

Syntax: RSEG segment

Description:

The RSEG statement selects a relocatable segment that was previously declared using the
SEGMENT statement.

Example
MYPROG

SEGMENT CODE

; Declare the segment

RSEG

MYPROG

; Select the segment

6. IF Assembler Statement

Syntax:

Description:

IF expression

a. The IF statement begins an IF-ELSE-ENDIF construct that is used for conditional


program assembly. The specified expression is evaluated and, if the value is non-zero
(TRUE), the code inside the IF block is assembled. If the expression is zero (FALSE),
the IF block is not assembled and subsequent blocks of the construct are evaluated.
b. IF blocks are terminated by an ELSEIF, ELSE, or ENDIF statement.
c. IF-ELSE-ENDIF blocks may be nested up to 10 deep.
Note:
a. The specified expression may not contain symbols defined with the SET and RESET
directives.
b. Do not confuse the IF statement with the $IF directive. They are not equivalent and
they may not be used with the same symbols.

Example:

Page | 5

IF (SWITCH = 1)
.
ELSEIF (SWITCH = 2)
.
ELSE
.
ENDIF
7. IF Assembler Directive

Arguments: IF expression

Description:

a. The IF directive begins an IF-ELSE-ENDIF construct that is used for conditional


program assembly. The specified expression is evaluated and, if the value is non-zero
(TRUE), the code inside the IF block is assembled. If the expression is zero (FALSE),
the IF block is not assembled and subsequent blocks of the construct are evaluated.
b. IF blocks are terminated by an ELSEIF, ELSE, or ENDIF directive.
c. IF-ELSE-ENDIF blocks may be nested up to 10 deep.
Note:
a. The specified expression may contain only those symbols defined using the SET and
RESET directives. Symbols defined with the EQU and SET statements may not be
used with the IF directive.
b. Do not confuse the IF directive with the IF statement. They are not equivalent and
they may not be used with the same symbols.
c. This directive may not be specified on the command line. It must be specified in a
source file.

Example
$IF (SWITCH = 1)
$ELSEIF (SWITCH = 2)
Page | 6

$ELSE
$ENDIF
8. SET Assembler Directive

Arguments:

SET (symbol = number , symbol = number ... )

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

SET (DEBUG_INFO=3, TEST)

$SET (ITERATION=4, DEBUG_VAR)

Page | 7

Você também pode gostar