Syntax. NXP CodeWarrior Development Studio
広告
広告
Chapter 12
Assembler
This chapter describes the assembler:
•
•
•
•
12.1 Syntax
This section describes the syntax of assembly language statements. It consists of these topics:
•
•
•
•
•
•
•
12.1.1 Assembly Language Statements
The three types of assembly language statements are:
• Machine instructions
• Macro calls
• Assembler directives
CodeWarrior Development Studio for Power Architecture Processors Build Tools Reference Manual, Rev.
10.6, 02/2014
Freescale Semiconductor, Inc.
155
Syntax
Instructions, directives, and macro names are case insensitive: the assembler considers
LWZ, Lwz, and lwz to be the same instruction
Remember these rules for assembly language statements:
1. The maximum length of a statement or an expanded macro is 512 characters.
2. A statement must reside on a single line. However, you can concatenate two or more lines by typing a backslash (\) character at the end of the line.
3. Each line of the source file can contain only one statement unless the assembler is running in GNU mode. (This mode allows multiple statements on one line, with semicolon separators.)
12.1.2 Statement Syntax
Statement Syntax shows the syntax of an assembly language statement.
Table 12-1 describes the elements of this syntax.
Listing: Statement Syntax
statement ::= [
symbol ]
operation [
operand ] [ ,
operand ]... [
comment ]
operation ::=
machine_instruction |
assembler_directive |
macro_call
operand ::=
symbol |
constant |
expression |
register_name symbol machine_instruction assembler_directive macro_call constant expression
Element
Table 12-1. Syntax Elements
Description
A combination of characters that represents a value.
A machine instruction for your target processor.
A special instruction that tells the assembler how to process other assembly language statements. For example, certain assembler directives specify the beginning and end of a macro.
A statement that calls a previously defined macro.
A defined value, such as a string of characters or a numeric value.
A mathematical expression.
Table continues on the next page...
CodeWarrior Development Studio for Power Architecture Processors Build Tools Reference Manual, Rev.
10.6, 02/2014
156 Freescale Semiconductor, Inc.
register_name comment
Chapter 12 Assembler
Table 12-1. Syntax Elements (continued)
Element Description
The name of a register; these names are processor-specific.
Text that the assembler ignores, useful for documenting your code.
12.1.3 Symbols
A symbol is a group of characters that represents a value, such as an address, numeric constant, string constant, or character constant. There is no length limit to symbols.
The syntax of a symbol is:
symbol ::= label | equate
In general, symbols have file-wide scope. This means:
1. You can access the symbol from anywhere in the file that includes the symbol definition.
2. You cannot access the symbol from another file.
However, it is possible for symbols to have a different scope, as described in the following sub-sections.
•
•
•
•
•
•
12.1.3.1 Labels
A label is a symbol that represents an address. A label's scope depends on whether the label is local or non-local.
The syntax of a label is:
CodeWarrior Development Studio for Power Architecture Processors Build Tools Reference Manual, Rev.
10.6, 02/2014
Freescale Semiconductor, Inc.
157
Syntax
label ::= local_label [ : ] | non-local_label[ : ]
The default settings are that each label ends with a colon (:), a label can begin in any column. However, if you port existing code that does not follow this convention, you should clear the Labels must end with ':' checkbox of the Assembler settings. After you clear the checkbox, you may use labels that do not end with colons, but such labels must begin in column 1.
12.1.3.2 Non-Local Labels
A non-local label is a symbol that represents an address and has file-wide scope. The first character of a non-local label must be a:
• letter (a-z or A-Z),
• period (.),
• question mark (?), or an
• underscore (_).
Subsequent characters can be from the preceding list or a:
• numeral (0-9), or
• dollar sign ($).
12.1.3.3 Local Labels
A local label is a symbol that represents an address and has local scope: the range forward and backward within the file to the points where the assembler encounters nonlocal labels.
The first character of a local label must be an at-sign (@). The subsequent characters of a local label can be:
• letters (a-z or A-Z)
• numerals (0-9)
• underscores (_)
• question marks (?)
• dollar sign. ($)
• periods (.)
CodeWarrior Development Studio for Power Architecture Processors Build Tools Reference Manual, Rev.
10.6, 02/2014
158 Freescale Semiconductor, Inc.
Chapter 12 Assembler
NOTE
You cannot export local labels; local labels do not appear in debugging tables.
Within an expanded macro, the scope of local labels works differently:
• The scope of local labels defined in macros does not extend outside the macro.
• A non-local label in an expanded macro does not end the scope of locals in the unexpanded source.
Local Label Scope in a Macro shows the scope of local labels in macros: the
@SKIP
label defined in the macro does not conflict with the
@SKIP
label defined in the main body of code.
Listing: Local Label Scope in a Macro
MAKEPOS .MACRO
cmpwi 0,r3,0
bge @SKIP
neg r3,r3
@SKIP: ; Scope of this label is within
; the macro
.ENDM
START:
lwz r3,COUNT
cmpw 0,r3, r4
beq @SKIP
MAKEPOS
@SKIP: ; Scope of this label is START to
; END excluding lines arising
; from macro expansion
addic r3,r3,1
END: blr
12.1.3.4 Relocatable Labels
The assembler assumes a flat 32-bit memory space. You can use the expressions of Table
12-2 to specify the relocation of a 32-bit label.
CodeWarrior Development Studio for Power Architecture Processors Build Tools Reference Manual, Rev.
10.6, 02/2014
Freescale Semiconductor, Inc.
159
Syntax
label
label@l
label@h
label@ha
label@sdax
label@got
NOTE
The assembler for your target processor may not allow all of these expressions.
Table 12-2. Relocatable Label Expressions
Expression Represents
The offset from the address of the label to the base of its section, relocated by the section base address. It also is the
PC-relative target of a branch or call. It is a 32-bit address.
The low 16-bits of the relocated address of the symbol.
The high 16-bits of the relocated address of the symbol. You can OR this with label@l to produce the full 32-bit relocated address.
The adjusted high 16-bits of the relocated address of the symbol. You can add this to label@l to produce the full 32-bit relocated address.
For labels in a small data section, the offset from the base of the small data section to the label. This syntax is not allowed for labels in other sections.
For processors with a global offset table, the offset from the base of the global offset table to the 32-bit entry for label.
12.1.3.5 Equates
An equate is a symbol that represents any value. To create an equate, use the
.equ
or
.set
directive.
The first character of an equate must be a:
• letter (a-z or A-Z),
• period (.),
• question mark (?), or
• underscore (_)
Subsequent characters can be from the preceding list or a:
• numeral (0-9) or
• dollar sign ($).
CodeWarrior Development Studio for Power Architecture Processors Build Tools Reference Manual, Rev.
10.6, 02/2014
160 Freescale Semiconductor, Inc.
Chapter 12 Assembler
The assembler allows forward equates. This means that a reference to an equate can be in a file before the equate's definition. When an assembler encounters such a symbol whose value is not known, the assembler retains the expression and marks it as unresolved. After the assembler reads the entire file, it reevaluates any unresolved expressions. If necessary, the assembler repeatedly reevaluates expressions until it resolves them all or cannot resolve them any further. If the assembler cannot resolve an expression, it issues an error message.
NOTE
The assembler must be able to resolve immediately any expression whose value affects the location counter. If the assembler can make a reasonable assumption about the location counter, it allows the expression.
The code of
shows a valid forward equate.
Listing: Valid Forward Equate
.data
.long alloc_size alloc_size .set rec_size + 4
; a valid forward equate on next line rec_size .set table_start-table_end
.text
;...
table_start:
; ...
table_end:
However, the code of Invalid Forward Equate is not valid. The assembler cannot
immediately resolve the expression in the
.space
directive, so the effect on the location counter is unknown.
Listing: Invalid Forward Equate
;invalid forward equate on next line rec_size .set table_start-table_end
.space rec_size
.text; ...
table_start:
; ...
table_end:
CodeWarrior Development Studio for Power Architecture Processors Build Tools Reference Manual, Rev.
10.6, 02/2014
Freescale Semiconductor, Inc.
161
Syntax
12.1.3.6 Case-Sensitive Identifiers
The Case-sensitive identifiers checkbox of the Assembler settings panel lets you control case-sensitivity for symbols:
• Check the checkbox to make symbols case sensitive -
SYM1
, sym1
, and
Sym1
are three different symbols.
• Clear the checkbox to make symbols not case-sensitive -
SYM1
, sym1
, and
Sym1
are the same symbol. (This is the default setting.)
12.1.4 Constants
The assembler recognizes three kinds of constants:
•
•
•
12.1.4.1 Integer Constants
Table 12-3 lists the notations for integer constants. Use the preferred notation for new code. The alternate notations are for porting existing code.
Hexadecimal
Decimal
Binary
Type
Table 12-3. Preferred Integer Constant Notation
Preferred Notation
$ followed by string of hexadecimal digits, such as $deadbeef.
String of decimal digits, such as
12345678.
% followed by a string of binary digits, such as %01010001.
Alternate Notation
0x followed by a string of hexadecimal digits, such as 0xdeadbeef.
0 followed by a string of hexadecimal digits, ending with h, such as
0deadbeefh.
String of decimal digits followed by d, such as 12345678d.
String of binary digits followed by b, such as 01010001b.
CodeWarrior Development Studio for Power Architecture Processors Build Tools Reference Manual, Rev.
10.6, 02/2014
162 Freescale Semiconductor, Inc.
NOTE
The assembler uses 32-bit signed arithmetic to store and manipulate integer constants.
Chapter 12 Assembler
12.1.4.2 Floating-Point Constants
You can specify floating-point constants in either hexadecimal or decimal format. The decimal format must contain a decimal point or an exponent. Examples are
1E-10
and
1.0
.
You can use floating-point constants only in data generation directives such as
.float
and
.double
, or in floating-point instructions. You cannot such constants in expressions.
12.1.4.3 Character Constants
Enclose a character constant in single quotes. However, if the character constant includes a single quote, use double quotes to enclose the character constant.
NOTE
A character constant cannot include both single and double quotes.
The maximum width of a character constant is 4 characters, depending on the context.
Examples are
'A'
,
'ABC'
, and
'TEXT'
.
\r
\t
\b
\n
\"
\\
\nnn
A character constant can contain any of the escape sequences that Table 12-4 lists.
Table 12-4. Character Constant Escape Sequences
Sequence Description
Backspace
Line feed (ASCII character 10)
Return (ASCII character 13)
Tab
Double quote
Backslash
Octal value of \nnn
During computation, the assembler zero-extends a character constant to 32 bits. You can use a character constant anywhere you can use an integer constant.
CodeWarrior Development Studio for Power Architecture Processors Build Tools Reference Manual, Rev.
10.6, 02/2014
Freescale Semiconductor, Inc.
163
Syntax
12.1.5 Expressions
The assembler uses 32-bit signed arithmetic to evaluates expressions; it does not check for arithmetic overflow.
As different processors use different operators, the assembler uses an expression syntax similar to that of the C language. Expressions use C operators and follow C rules for parentheses and associativity.
NOTE
To refer to the program counter in an expression, use a period
(.), dollar sign ($), or asterisk (*).
Table 12-5 lists the expression operators that the assembler supports.
Table 12-5. Expression Operators
Binary
Unary
Category
|
&
^
<<
>>
/
%
||
&&
-
+
*
Operator
-
+
<
@
~
==
!=
<=
>=
>=
Table continues on the next page...
Description
add subtract multiply divide modulo logical OR logical AND bitwise OR bitwise AND bitwise XOR shift left shift right (zeros are shifted into high order bits) equal to not equal to less than or equal to greater than or equal to greater than or equal to less than at unary plus unary minus unary bitwise complement
CodeWarrior Development Studio for Power Architecture Processors Build Tools Reference Manual, Rev.
10.6, 02/2014
164 Freescale Semiconductor, Inc.
Alternate
Category
Chapter 12 Assembler
Table 12-5. Expression Operators (continued)
Operator
|
||
<>
% not equal to modulo logical OR logical XOR
Description
Operator precedence is:
1. unary
+ - ~
2.
* / %
3. binary
+ -
4.
<< >>
5.
< <= > >=
6.
== !=
7.
&
8.
^
9.
| @
10.
&&
11.
||
12.1.6 Comments
There are several ways to specify comments:
1. Use either type of C-style comment, which can start in any column:
// This is a comment.
or
/* This is a comment. */
2. Start the comment with an asterisk (*) in the first column of the line.
NOTE
The asterisk (*) must be the first character of the line for it to specify a comment. The asterisk has other meanings if it occurs elsewhere in a line.
3. Clear the Allow space in operand field checkbox of the Assembler settings panel.
Subsequently, if you type a space in an operand field, all the remaining text of the line is a comment.
4. Anything following a # character is considered to be a comment. For example, st r3,0(r4) # Store total
CodeWarrior Development Studio for Power Architecture Processors Build Tools Reference Manual, Rev.
10.6, 02/2014
Freescale Semiconductor, Inc.
165
ダウンロード
広告