Keil Software — A51/AX51/A251 Macro Assembler and Utilities 99 Shaded directives and options are available only in AX51 and A251. 4 Chapter 4. Assembler Directives This chapter describes the assembler directiv es. It shows how to define symbols and how to control the p lacement of code and data in program memory. Introduction The A x51 assembler has several directives that permit you to defin e symbol values, reserve and initialize storage, and control the placement of your code. The directives should not be confused with instructions. They do not produce executable code, and with the ex ception of the DB, DW and DD directives, they have no direct effect on the contents of code memory . These directives change the state of the assembler, define user symbols, and add information to the obj ect file. The following table provides an ov erview of the assembler directives. Page refers to the page number in this us er’s guide where you can find d etailed information about the directive. Directive / Page Format Description BIT 114symbolBIT bit_address Define a bit address in bit data space. BSEG 111BSEG [AT absolute address] Define an absolute segment within the bit address space. CODE 114symbolCODE code_addressAssign a symbol name to a specific address in the code space. CSEG 111CSEG [AT absolute address] Define an absolute segment within the code address space. DATA 114symbolDATA data _addressAssign a symbol name to a specific on-chip data address. DB 119[label:] DB expression [, expr...] Generate a list of byte values. DBIT 122[label:] DBIT expressionReserve a space in bit units. DD 121[label:] DD expression [, expr...] Generate a list of double word values. DS 123[label:] DS expressionReserve space in byte units. DSB 124[label:] DSB expressionReserve space in byte units. DSD 126[label:] DSD expressionReserve space in double word units. DSEG 111DSEG [AT absolute address] Define an absolute segment within the indirect internal data space. used in xxx.inc
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Keil Software — A51/AX51/A251 Macro Assembler and Utilities 99
Shaded directives and options are available only in AX51 and A251.
4
Chapter 4. Assembler Directives
This chapter describes the assembler directives. It shows how to define symbols
and how to control the placement of code and data in program memory.
Introduction
The A x 51 assembler has several directives that permit you to define symbolvalues, reserve and initialize storage, and control the placement of your code.
The directives should not be confused with instructions. They do not produce
executable code, and with the exception of the DB, DW and DD directives, they
have no direct effect on the contents of code memory. These directives change
the state of the assembler, define user symbols, and add information to the object
file.
The following table provides an overview of the assembler directives. Page
refers to the page number in this user’s guide where you can find detailed
information about the directive.
Directive / Page Format Description
BIT 114 symbol BIT bit_address Define a bit address in bit data space.BSEG 111 BSEG [AT absolute address] Define an absolute segment within the
bit address space.
CODE 114 symbol CODE code_address Assign a symbol name to a specificaddress in the code space.
CSEG 111 CSEG [AT absolute address] Define an absolute segment within thecode address space.
DATA 114 symbol DATA data _ address Assign a symbol name to a specificon-chip data address.
DB 119 [label :] DB expression [, expr ...] Generate a list of byte values.
DBIT 122 [label :] DBIT expression Reserve a space in bit units.
DD 121 [label :] DD expression [, expr ...] Generate a list of double word values.
DS 123 [label :] DS expression Reserve space in byte units.
DSB 124 [label :] DSB expression Reserve space in byte units.
DSD 126 [label :] DSD expression Reserve space in double word units.
DSEG 111 DSEG [AT absolute address] Define an absolute segment within the
Keil Software — A51/AX51/A251 Macro Assembler and Utilities 107
Shaded directives and options are available only in AX51 and A251.
4
Class
The name of each segment within a module must be unique. However, the linker will combine segments having the same segment type. This applies to segments
declared in other source modules as well.
The class specifies the memory class space for the segment. The A251
differentiates between basic classes and user-defined classes. The class is used
by the linker/locator to access all the segments which belong to that class.
The basic classes are listed below:
Basic Class Description
BIT BIT space (address 20H .. 2FH).
CODE CODE space
CONST CONST space; same as CODE but for constant only; access via MOVC.
DATA DATA space (address 0 to 7FH & SFR registers).
EBIT Extended 251 bit space (address 20H .. 7FH)
EDATA EDATA space
ECONST ECONST space; same as EDATA but for constants
IDATA IDATA space (address 0 to 0FFH).
ECODE Entire Intel/Atmel WM 251 and Philips 80C51MX address space for programcode.
HCONST Entire Intel/Atmel WM 251 and Philips 80C51MX address space for constants.
HDATA Entire Intel/Atmel WM 251 and Philips 80C51MX address space for data.
XDATA XDATA space; access via MOVX.
User -defined Class Names (AX51 & A251 only)
User-defined class names are composed of a basic class name and an extension
and are enclosed in single quotes ('). They let you access the same address spaceas basic class names. The advantage is that you may declare several segments
with a user-defined class and later use the linker to locate that class (and its
segments) at a specific physical address. Refer to the “CLASSES” on page 336
for information on how to locate user defined classes.
Keil Software — A51/AX51/A251 Macro Assembler and Utilities 111
Shaded directives and options are available only in AX51 and A251.
4
BSEG, CSEG, DSEG, ISEG, XSEG
The BSEG, CSEG, DSEG, ISEG, XSEG directives select an absolute segment.This directives use the following formats:
BSEG AT address defines an absolute BIT segment.CSEG AT address defines an absolute CODE segment.DSEG AT address defines an absolute DATA segment.ISEG AT address defines an absolute IDATA segment.XSEG AT address defines an absolute XDATA segment.
where
address is an optional absolute base address at which the segment
begins. The address may not contain any forward
references and must be an expression that can be evaluated
to a valid address.
CSEG, DSEG, ISEG, BSEG and XSEG select an absolute segment within thecode, internal data, indirect internal data, bit, or external data address spaces. If
you choose to specify an absolute address (by including AT address), the
assembler terminates the last absolute segment, if any, of the specified segment
type, and creates a new absolute segment starting at that address. If you do not
specify an address, the last absolute segment of the specified type is continued.
If no absolute segment of this type was selected and the absolute address is
omitted, a new segment is created starting at location 0. You cannot use any
forward references and the start address must be an absolute expression.
The AX51 and A251 Macro Assembler supports the BSEG, CSEG, DSEG,
Keil Software — A51/AX51/A251 Macro Assembler and Utilities 119
Shaded directives and options are available only in AX51 and A251.
4
Memory Initialization
The memory initialization directives are used to initialize code or constant spacein either word, double-word, or byte units. The memory image starts at the point
indicated by the current value of the location counter in the currently active
segment.
DB
The DB directive initializes code memory with 8-bit byte values. The DB
directive has the following format:
label: DB expression , expression …
where
label is the symbol that is given the address of the initializedmemory.
expression is a byte value. Each expression may be a symbol, a
character string, or an expression.
The DB directive can only be specified within a code or const segment. If the
DB directive is used in a different segment, A x 51 will generate an error message.
Example
REQUEST: DB 'PRESS ANY KEY TO CONTINUE', 0TABLE: DB 0,1,8,'A','0', LOW(TABLE),';'ZERO: DB 0, ''''CASE_TAB: DB LOW(REQUEST), LOW(TABLE), LOW(ZERO)
Shaded directives and options are available only in AX51 and A251.
4
Reserving Memory
The memory reservation directives are used to reserve space in either word,dword, byte, or bit units. The space reserved starts at the point indicated by the
current value of the location counter in the currently active segment.
DBIT
The DBIT directive reserves space in a bit or ebit segment. The DBIT directive
has the following format:
label: DBIT expression
where
label is the symbol that is given the address of the reserved
memory. The label is a symbol of the type BIT and gets thecurrent address value and the memory class of the active
segment. The label can only be used where a symbol of this
type is allowed.
expression is the number of bits to reserve. The expression cannot
contain forward references, relocatable symbols, or external
symbols.
The DBIT directive reserves space in the bit segment starting at the current
address. The location counter for the bit segment is increased by the value of the
expression. You should note that the location counter for the bit segment
references bits and not bytes.
NOTE The Ax51 assembler is a two–pass assembler. Symbols are collected and the
length of each instruction is determined in the first pass. In the second pass,
forward references are resolved and object code is produced. For these
reasons, an expression used with the DBIT directive may not contain forward
Keil Software — A51/AX51/A251 Macro Assembler and Utilities 123
Shaded directives and options are available only in AX51 and A251.
4
DS
The DS directive reserves a specified number of bytes in a memory space. TheDS directive has the following format:
label: DS expression
where
label is the symbol that is given the address of the reserved
memory. The label is a typeless number and gets the currentaddress value and the memory class of the active segment.
The label can only be used where a symbol of this type is
allowed.
expression is the number of bytes to reserve. The expression cannot
contain forward references, relocatable symbols, or external
symbols.
The DS directive reserves space in the current segment at the current address.
The current address is then increased by the value of the expression. The sum
of the location counter and the value of the specified expression should not
exceed the limitations of the current address space.
NOTE
The A251 assembler is a two–pass assembler. Symbols are collected and thelength of each instruction is determined in the first pass. In the second pass,
forward references are resolved and object code is produced. For these
reasons, an expression used with the DS directive may not contain forward