9 Writing Machine Language Instruction Statements and Directive Statements. Panasonic MN1030, MN1030 Series
Реклама
Реклама
Chapter 9 Writing Machine Language Instruction
Statements and Directive Statements
9
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.1
Purpose of This Chapter
This chapter explains how to write machine language instructions and directives.
There are five source statement formats
• Instruction statements that code machine language instructions and directives.
• Assembler control statements that code assembler control instructions
• Macro control statements that code macro control instructions
• Comment statements
• Blank statements
Each is coded differently.
This chapter explains in detail the code syntax and usage examples of machine language instructions and directives.
Refer to Chapter 8, "Writing Source Statements", regarding address constants, numeric constants, expressions, and the syntax rules for numbers and characters.
Refer to the "Instruction Manual" for detailed descriptions of machine language instructions.
146 Purpose of This Chapter
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.2
Instruction Statement Fields
Source statements that code machine language instructions and directives are built from four fields.
[label] [operation [operand [, operand]]] [comment]
Contents of brackets [ ] can be omitted.
Coding rules
Source statements may contain a label field only.
Depending on the operation, source statements may contain no operand.
Fields are delimited by at least one space or tab. Two operands are delimited by a comma (,).
A statement with an LF only, omitting all fields, is a blank statement.
Statements are terminated by the LF character (line feed = 0x0A).
The maximum number of characters on one line is 255.
Instruction Statement Fields 147
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.2.1
Writing Label Field
Labels are called both symbols and names. The assembler assigns a label the value of the location counter at the point it is defined.
Coding rules
Labels can use upper-case and lower-case letters, digits, underscores (_).
Labels are coded in the first column.
The first character of a label must not be a digit.
Labels are case sensitive.
The same label name cannot be defined twice.
When the label is omitted, it must be replaced with at least one space or tab.
Terminology: * Column
This is a column on the display or printer paper. One character takes one column. Columns are counted from the left as column 1, 2, etc.
Coding examples
LABEL
LONGLABELLONGLABELLONGLABELLONGLAB main start_cont
The following examples are incorrect.
1LABEL
@START
START
; Starts with a digit
; Uses a prohibited character
; Does not start from the first column
148 Instruction Statement Fields
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.2.2
Writing Operation Field
The operation field is written with a machine language instruction or directive.
Coding rules
Machine language instructions cannot mix case. They must use either upper or lower case throughout.
Coding examples
CONST1
_CODE start equ section mov rts
10
CODE, PUBLIC, 2
CONST1, D0
Instruction Statement Fields 149
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.2.3
Writing Operand Field
The operand field coding is determined by the machine language instruction or directive in the operation field. Refer to the "Instruction Manual" for details on coding machine language instructions.
Coding rules
Operands are written with expressions and reserved words (register names, etc.).
Operands cannot include spaces, except for character constants and string constants.
When two operands are coded, they must be delimited by a comma (,).
Coding examples
ROL mov jsr
D0
CONST+3, D0
;One operand
;Operands are register and expression
;Operand is an address
150 Instruction Statement Fields
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.2.4
Writing Comment Field
The field that starts from a semicolon (;) after the operands is called the comment field. Comments coded in this position are called end-of-line comments, as opposed to comment statements where the entire line is a comment.
Coding rules
Comments being with a semicolon (;) and end with a line feed (LF).
Comment fields may be written with letters, digits, special characters, and control characters other than carriage return and line feed.
Coding examples mov 0x10, D0
;Set count value
Instruction Statement Fields 151
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.3
Writing Machine Language Instruction
Statements
Each machine language instruction is defined by specific mnemonics. Mnemonics are formed from operations and operands accurately coded in the statement fields previously described.
Both upper-case and lower-case letters may be used.
Refer to the "Instruction Manual" for details of machine language instructions.
Coding rules
When coding a label, insert at least one space or tab between it and the operation field.
When the label field is omitted, replace it with at least one space or tab.
Both upper-case and lower-case letters may be used.
Insert at least one space or tab between the operation field and operand field.
The assembler and linker optimization function will adjust conditional and unconditional branch instructions to generate the optimal code.
When a relative address is specified in an operand and only labels with specific addresses are coded, the assembler will calculate and set the relative values.
Coding examples
START add sub mul divu cmp bra jmp jsr rts mov mov not rol ror and or xor
D0, (A0)
;src=register, dst=register indirect
0x11, D0 ;src=immediate data, dst=register
D0
;negate
D0
D0
;rotate left
;rotate right
0x0f, D0 ;logical AND
0x30, D0
;logical OR
D0, D1
D1, D0
D1, D0
D1, D0
;exclusive OR
;addition
;subtraction
;multiplication
D1, D0 ;division
0x05, D0
;comparison
SUBR
(A0)
SUBR
;unconditional branch
;unconditional branch(register indirect)
;subroutine call
;return from subroutine
152 Writing Machine Language Instruction Statements
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.4
Writing Directive Statements
Directives differ from machine language instructions in that they only have effect on the assembler.
Directives specify program structure and start addresses, set constants and radices, and specify options and label attributes.
List of directives
Below is a list of directives.
Directive page radix dc ds dw dd equ global section align end listoff liston notation org opt tit xlistoff xliston funcinfo assign
Function
Specifies a section
Aligns the location counter value to a multiple of an expression.
Indicates the end of the program.
Stops list output from the line following this directive.
Starts list output from this directive.
Selects the coding format for numbers.
Changes the program address.
Enables/disables optimization functions.
Specifies the number of columns and rows on one page of the list file.
Selects the radix to be specified by default.
Stores an 8-bit constant in a memory area.
Reserves an 8-bit data area in a memory area.
Stores a 16-bit constant in a memory area.
Stores a 32-bit constant in a memory area.
Defines a name as the value of an operand expression.
Declares external references with external declarations.
Specifies the header name of the list file.
Stops list output including this directive.
Starts list output from the line following this directive.
Specifies additional information for a function.
Defines a name as the value of an operand expression.
Document conventions
Symbols used in this chapter have the following meanings.
|
[ ]
( )...
Contents of brackets [ ] may be omitted.
Contents of parentheses ( ) may be repeated.
Specify one or the other of the terms delimited by a vertical bar |.
Writing Directive Statements 153
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.4.1
section
Syntax label operation section_name section operand
[definition1 [,definition2 [,expression]]] definition1 Section attribute (CODE or DATA) definition2 Link type (PUBLIC)
(Note that the words PRIVATE and COMMON are reserved for use in expansion.
However, they are treated as PUBLIC for now.) expression Alignment factor for the location counter (2 to the specified power)
Default settings
If the section name appears for the first time in the file, the following defaults are used.
definition1 CODE definition2 PUBLIC expression 1
For subsequent appearances of the section name, the section inherits the values from previous appearances.
Functional description
The section directive specifies a section name, as well as its attribute, link type, and location boundary.
During linking the linker gathers sections with the same name and links them together by attribute. The order of linking is determined by the link type and the order in which the linker encounters the sections.
Section linking rules
1. Link sections in order of appearance.
2. Link by attribute.
3. Link by link type.
PUBLIC Link across all linked files.
154 Writing Directive Statements
Chapter 9 Writing Machine Language Instructions and Directive Statements
Operand coding rules
Only specific strings can be defined for definition1 and definition2. If some other string is defined, the assembler will generate an error and ignore this directive.
The value of expression must be a power of 2 between 1 and 32768, or 0. If its value is outside this range, the assembler will assume the closest valid value instead.
The attribute, link type, and location boundary of sections with the same name must be either identical or omitted. If a different attribute, link type, or location boundary is defined, actual value will be inherited from the setting of the very first section.
If there is the same section name in a file with a different attribute, link type, or location boundary, the linker warns.
Directive coding rules
The section directive has no restrictions on where in the source file it can be defined.
Usage example
Below is an example use of the section directive.
_CODE main section jsr INIT
.
.
.
CODE, PUBLIC, 2
NOTE: Assembler instructions and dc, dw, ds and dd directives must be coded after a section has been defined. If used before a section has been defined, the assembler will generate an error and ignore that assembler instruction or directive.
NOTE: The value for the section name will be the starting address in the same section after link. If separating the sections, the starting address of the lowest section will be used.
Writing Directive Statements 155
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.4.2
align
Syntax label operation align operand expression
Default settings
The current location counter value will be inherited.
Functional description
The align directive adjusts the location counter to be a multiple of the value indicated by expression.
The expression must be a power of 2 in the range 1 to 2
15
.
When the expression value is 4, the multiples of 4 will be the following series.
4, 8, 12, 16, 20, 24, 28, 32, ...
When the location counter value is 13, the statement after align 4 will have its location counter changed to 16. When the location counter is 23, the statement will have its location counter changed to 24.
When the location counter is 30, the statement counter will have its location counter changed to 32.
Thus, the align directive rounds up the current location counter value up to the next greater multiple of the expression value.
Operand coding rules
The attribute of the calculated result of the expression coded in the operand must be abs (absolute). For a discussion of expression attributes, see Chapter 8 “Writing Source Statements” Section 8.7
“Expressions”, 8.7.4 ”Expression Attributes”.
The expression value must be a power of 2 in the range 1 to 2
15
.
2, 4, 8, 16, 32, 64, 128, 256, ...
If the expression value is not a power of 2, the assembler will generate an error and round up to the next greater power of 2. In such a case, if the assembler's r option has been specified, the assembler will generate a relocatable object file even with the error.
When the expression value is between 5 to 7, it can be round up to 8. Also, when the expression value is between 17to 31,it can be round up to 32.
156 Writing Directive Statements
Chapter 9 Writing Machine Language Instructions and Directive Statements
Usage example
Below is an example use of the align directive.
Loc align.lst Page 1
*** PanaX Series MN1030 Cross Assembler ***
Object Line
1
2
Source
_DATA
TABLE section ,DATA, PUBLIC, 4
00000000
00000000
00000001
00000002 dc dc dc
6 align align.asm(6) :Warning 2002: Illegal operand value.
00000008 04 7 dc
00000009
0000000a
05
06
8
9
10 dc dc align
00000010
00000011
00000020
00000021
01
02
03
07
08
09
0A
3
4
5
11
12
13
14
15 dc dc align dc dc
0x01
0x02
0x03
6
0x04
0x05
0x06
8
0x07
0x08
16
0x09
0x0a
Errors: 0 Warnings: 1 (align.asm)
In the align 6 directive on line 6, the expression value 6 is not a power of 2, so the assembler will convert it to align 8.
The series of multiples of 8 is shown below. Numbers in parentheses are hexadecimal.
8(8) 16(10) 24(18) 32(20) 40(28) 48(30) 56(38) 64(40)
The location counter value at the line of align 6 is 0003 (hex.), which is between 0000 and 0008 (hex.).
Therefore the next line will start from location 0008 (hex.).
The same series applies to the align 8 on line 10. The location counter there is 000B (hex.), which is between 0008 and 0010 (hex.). Therefore the next line will start from location 0010 (hex.).
Similarly, the align 16 on line 13 uses the series 16 (10), 32 (20), 48 (30)... The location counter there is 0012 (hex.), which is between 0010 and 0020 (hex.). Therefore the next line will start from location
0020 (hex.).
Writing Directive Statements 157
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.4.3
end
Syntax label
[name] operation operand end
Default settings
If the end directive is omitted, the assembler file will assume that the end of the file is the end of the program.
Functional description
This directive is coded once at the end of a program. All text coded after the end directive will be ignored by the assembler (but it will be output to the source list).
When a name is coded in the label field, the current location counter value will be assigned to it.
Operand coding rules
The end directive takes no operands. If operands are coded, they will cause an assembler syntax error.
Usage example
Below is an example use of the end directive.
_CODE main section
.
.
jsr mov end
CODE, PUBLIC, 2 data_move
0, D0
158 Writing Directive Statements
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.4.4
listoff, liston
Syntax label
[name]
[name] operation listoff
.
.
.
liston operand
Functional description
The listoff and liston directives are used in pairs. Statements from the statement following the listoff directive until the statement preceding the liston directive will not be output to the list file. These directives are used when you do not want to output an already debugged program to the list file.
NOTE: The listoff and liston directives themselves are output.
Only output to the list file will be suppressed. Output of object code will not be suppressed at all.
Operand coding rules
These directives take no operands.
Usage example
Below is an example use of the listoff and liston directives. The mov 0x22,D0 is a statement that should not be output to the list file.
_CODE main section mov listoff mov liston mov end
CODE, PUBLIC, 2
0x11, D0
0x22, D0
0x33, D0
Writing Directive Statements 159
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.4.5
notation
Syntax label operation notation operand
CLANG | INTE | PANA
Default settings
CLANG will be selected.
Functional description
This directive selects the format of numbers and character constants (single character).
The Cross-Assembler provides three numeric formats.
• Extended C language format
• Intel format
• Matsushita format
Each format gives a specific way to represent binary, octal, decimal, and hexadecimal numbers, as well as character constants.
The notation directive selects which format numbers and character constants will be coded with. This directive can be coded any number of times in a program.
Refer to Chapter 8 “Writing Source Statements”, section 8.7, "Expressions”, section 8.7.4 “Expression
Attributes”.
Operand coding rules
The strings that can be specified in the operand and the format that they select are listed below.
operand
CLANG
INTEL
PANA
Format
Extended C language format
Intel format
Matsushita format
If other strings are specified, the assembler will generate an error and ignore this directive.
160 Writing Directive Statements
Chapter 9 Writing Machine Language Instructions and Directive Statements
Usage example
Below is an example use of the notation directive.
Loc
00000000
00000001
00000002
00000003
00000004
00000005
00000006
00000007
00000008
00000009
0000000a
0000000b
0000000c notation.lst page 1
*** PanaX Series MN1030 Cross Assembler ***
Object
FF
FF
FF
FF
FF
FF
FF
FF
FF
FF
FF
FF
FF
Line
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Source
_DATA section CODE, PUBLIC, 4 notation INTEL dc dc dc dc dc notation CLANG dc dc dc dc notation dc dc dc dc
11111111b
377q
377o
255d
0ffh
0b11111111
0377
255
0xff
PANA b’11111111’ o’377’ f’255’ x’ff’
Writing Directive Statements 161
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.4.6
org
Syntax label operation org operand expression
Default settings
The current location counter value will be inherited.
Functional description
This directive sets the location counter to the address value specified by expression.
Operand coding rules
For the expression coded in the operand, the attribute of the calculation result must be abs(absolute).
For a discussion of attributes of expressions, see Chapter 8 “Writing Source Statements” Section 8.7
“Expressions” Section 8.7.4 “Expression Attributes”.
If the expression value is less than the current location counter, it causes an error.
Usage example
Below is an example use of the org directive.
_CODE sec_adr
CODE, PUBLIC, 2 sec_fnc section
.
instructions
.
org
.
instructions
.
org
.
.
.
end
0x20
0x100
162 Writing Directive Statements
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.4.7
opt
Syntax label operation opt operand on | off
Default settings
If omitted, opt off will be assumed.
Functional description
This directive enables and disables the optimization functions of the assembler and linker.
The optimization applies only to conditional and unconditional branch instructions. The optimization function evaluates how the source statements are coded, and converts them to the optimal code with the linker.
While the linker is linking multiple files, it outputs the instructions with the smallest possible code size for the instructions subject to optimization.
Refer to chapter 4, "Optimization", for details.
NOTE: The -Od assembler option disables the optimization function, however, optimization will be enabled if opt on is coded in the source file
Operand coding rules
The strings that can be coded for the operand and their meanings are as follows.
opt on Enables optimization.
opt off Disables optimization.
Usage example
Below is an example use of the opt directive.
opt opt on off
Writing Directive Statements 163
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.4.8
page
Syntax label operation page operand lines_expression [,columns_expression]
Default settings
Number of lines = 60
Number of columns = 132
Functional description
This directive specifies the number of lines and columns per page. At the line where the page directive itself is specified the assembler will output a carriage return and apply the newly set values.
Operand coding rules
The expressions coded in the operand must result in the attribute abs (absolute). Refer to section 8.7.4,
"Expression Attributes", regarding attributes of expressions.
Specify the number of lines in the range 10 – 255. Specify the number of columns in the range 60 –
255.
If a value outside the allowable range is specified, the assembler will generate an error and ignore this directive.
Usage example
Below is an example use of the page directive.
page page
24, 80
LINE_NO, COLUMN_NO
164 Writing Directive Statements
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.4.9
radix
Syntax label operation radix
Default settings
Radix 10 (decimal).
operand expression
Functional description
This directive specifies the radix that will be used by default. The Cross-Assembler provides three coding formats for numbers.
• Extended C language format
• Intel format
• Matsushita format
The format is selected with the notation directive. Refer to the description of the notation directive.
The default is extended C language format.
The radix directive specifies the default radix for numbers in these coding formats by the expression in the operand. Select one from radix 2 (binary), radix 8 (octal), radix 10 (decimal), and radix 16
(hexadecimal).
NOTE: In extended C language format, the default radix cannot be specified by the radix directive. The default is fixed as radix 10 (decimal), and it cannot be changed to another radix
Operand coding rules
The expression coded in the operand must result in the attribute abs (absolute). Refer to section 8.7.4,
"Expression Attributes", regarding attributes of expressions.
The calculated result of the expression coded in the operand must be either 2, 8, 10, or 16. The radix of the expression in the operand is always 10 (decimal), regardless of the current default radix. If the expression results in a number that does not specify a radix, the assembler will generate an error and ignore this directive.
Usage example
Below is an example use of the radix directive.
radix radix
16
BINARY
Writing Directive Statements 165
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.4.10 dc
Syntax label
[name] operation dc operand constant | expression (, constant | expression )...
Functional description
This directive is used to define constants in a memory area. The 8-bit constant specified by the operand will be stored at the location of the statement specifying this directive.
When a name is coded for the label, the assembler will assign the current location counter value to that name.
Operand coding rules
The expression coded in the operand must result in the attribute abs(absolute).
Refer to section 8.7.4 “Expression Attributes”, regafding attributes of expressions.
Specify one of the following constants or the operand.
• character constant
• string constant
The operands are delimited with commas (,). Any number of operands can be coded.
If data that exceeds 8 bits is specified, the lower 8 bits will be valid, and the upper bits will be lost. The assembler will output a warning message in such cases.
When the specified data has fewer than 8 bits, those bits will fill the lower bits, and the upper bits will be padded with zeroes.
Usage example
Below is an example use of the dc directive.
Loc
00000000
00000001
00000004
00000005
00000006
00000007
00000009
DC.LST
Page 1
*** PanaX Series MN1030 Cross Assembler ***
Object Line Source
1 _DATA section DATA,PUBLIC,4
41
414243
3F
0E
2
3
4
5 cd0 dc cd1 dc cd2 dc cd3 dc
’A’
“ABC”
255 >> 2
(12+3)/2*2
FF
FFFE
FF
6
7
8 cd4 dc cd5 dc cd6 dc
0b11111111
0377, 0376
255
166 Writing Directive Statements
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.4.11 ds
Syntax label
[name] expression1 expression2 operation ds expression3
Number of bytes of memory to reserve
Initial value operand expression1 [, expression2 [, expression3]]
Number of iterations
Default settings expression2 (initial value) If omitted, the assembler will assume 0.
expression3 (iterations) If omitted, the assembler will assume 1.
Functional description
This directive reserves a memory area of the number of bytes specified by expression1 of the operand.
When expression2 (initial value) is specified, that memory area will be filled with the initial value.
Note that expression2 can be specified only when the value of expression1 is 4 or less. When expression3 (iterations) is specified, the same specification will be repeated for the number of iterations. For example, if the operand is 4, 0, 3, a 4-byte area will be filled with 0 three times. Thus, a
12-byte area will be reserved.
When a name is coded for the label, the assembler will assign the current location counter value to that name.
Operand coding rules
The expression1 (bytes), expression2 (initial value), and expression3 (iterations) coded in the operand must result in the attribute abs (absolute). Refer to section 8.7.4, "Expression Attributes", regarding attributes of expressions.
NOTE: When expression2 is omitted, expression3 cannot be specified.
Writing Directive Statements 167
Chapter 9 Writing Machine Language Instructions and Directive Statements
Usage example
Below is an example use of the ds directive.
Loc
DC.LST
Page 1
*** PanaX Series MN1030 Cross Assembler ***
Object Line
1
Source
_DATA section DATA, PUBLIC, 4
00000000 00
00000001 1122
00000003 3344556633445566 4
2
3 ds0 ds
ds ds1 ds
1
2, 0x1122
4, 0x33445566,2
168 Writing Directive Statements
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.4.12 dw
Syntax label
[name] operation dw operand expression (, expression )...
Functional description
This directive is used to define 16-bit constants in a memory area. The 16-bit constant specified by the operand will be stored at the location of the statement specifying this directive.
When a name is coded for the label, the assembler will assign the current location counter value to that name.
Operand coding rules
The operands are delimited with commas (,). Any number of operands can be coded.
If data that exceeds 16 bits is specified, the lower 16 bits will be valid, and the upper bits will be lost.
The assembler will output a warning message in such cases.
When the specified data has fewer than 16 bits, those bits will fill the lower bits, and the upper bits will be padded with zeroes.
Usage example
Below is an example use of the dw directive.
Loc
00000000 dw.lst
Page 1
*** PanaX Series MN1030 Cross Assembler ***
Object Line Source
3930
00000002 34127856
00000006 0000
3
4
1
2
_DATA dw0 dw dw1 dw dw2 dw section DATA, PUBLIC, 4
12345
0x1234, 0x5678
0
Writing Directive Statements 169
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.4.13 dd
Syntax label
[name] operation dd operand expression(, expression)...
Functional description
This directive is used to define 32-bit constants in a memory area. The 32-bit constant specified by the operand will be stored at the location of the statement specifying this directive.
When a name is coded for the label, the assembler will assign the current location counter value to that name.
Operand coding rules
The operands are delimited with commas(,). Any number of operands can be coded.
When the specified data has fewer than 24 bits, those bits will fill the lower bits and the upper bits will be padded with zeros.
Usage example
Below is an example use of the dw directive.
Loc
1
2 dd.LST
;
Page 1
*** PanaX Series MN1030 Cross Assembler ***
Object Line Source global dd0, dd1, g_dd0
00000000 78563412
00000004 00000000
00000008 00000000
3
4
+5
+6
_DATA dd0 dd1 section DATA, PUBLIC, 4 dd 0x12345678 dd dd dd0 g_dd0
170 Writing Directive Statements
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.4.14 equ
Syntax label name operation equ operand expression
Functional description
This directive defines the name to be the value of the expression coded in the operand. When that name is coded in the operand of machine language instructions or directive instructions, the assembler will reference the name's value.
System constants often used in programs (memory size, clock frequency, etc.) can be assigned to names that describe those values.
MEMORY
MOTOR
STOP
BASE equ equ equ equ
0x20
10
0b00001000
0x1000
This allows numbers used in programs to be coded as descriptive names instead, making programs easier to read. Furthermore, values can be changed just by modifying the equ directive, which in turn changes the data wherever it is used. This makes programs easier to maintain.
Operand coding rules
The expression coded in the operand must result in the attribute abs (absolute). Refer to Section 8.7.4,
"Expression Attributes", regarding attributes of expressions.
If the attributes of expressions are not the attribute abs (absolute), #define of the assembler control statement should be used, instead of the equ of the directive statement..
Names defined in other programs cannot be specified within expression.
Names defined once with the equ directive cannot be defined again.
No memory area is reserved when an equ directive statement is executed.
NOTE: Symbols with unresolved values cannot be coded in the operand. In the following example, the value of ram1 is not resolved at the point where the value of ram2 is to be resolved, so the assembler will generate an error.
Error example: ram2 ram1 equ equ ram1+0x1
0x10
By changing the order such that the value of ram1 is resolved first, no error will occur.
No error example: ram1 equ ram2 equ
0x10 ram1+0x1
Writing Directive Statements 171
Chapter 9 Writing Machine Language Instructions and Directive Statements
Usage example
Below is an example use of the equ directive.
Loc equ.lst
Page 1
*** PanaX Series MN1030 Cross Assembler ***
Object Line Source
1 MEMORY equ 0x20
2
3
4
5
6
7
MOTOR
STOP
BASE
;
_TEXT equ equ equ
10
0b00001000
0x1000
00000000 8020
00000002 800A
00000004 8008
00000006 2C0010
8
9
10 section CODE, PUBLIC, 1 mov MEMORY, D0 mov mov mov
MOTOR, D0
STOP, D0
BASE, D0
172 Writing Directive Statements
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.4.15 global
Syntax label
[name] operation global operand name(, name)...
Default settings
External reference when omitted = undefined label error
External declaration when omitted = undefined label error during linking
Functional description
This directive declares external references and external declarations.
For external references, the global directive declares that the names coded in the operand are from other files.
For external declarations, the global directive declares that the names coded in the operand can be referenced externally.
The global directive can be coded anywhere in a source programs.
Operand coding rules
Write the name coded in the label field as an operand. Generally this will be a program name.
The names are delimited with commas (,). Any number of operands can be coded.
When a specified name has been coded in a label field within the program, it will be considered an external declaration. When it has been coded as operands, it will be considered an external reference.
Writing Directive Statements 173
Chapter 9 Writing Machine Language Instructions and Directive Statements
Usage example
Below is an example use of the global directive.
main
SUB1 global global jsr
.
.
jsr
.
.
mov
.
.
rts end
SUB1
READ,
WRITE
READ
WRITE
0x11, D0
;external declaration
;external reference
NOTE: If a section name was referred as an external label, declaration with the section directive, not with the global directive, is necessary.
Example: sec section CODE,PUBLIC,1
_TEXT section CODE,PUBLIC,1
mov sec, A0
174 Writing Directive Statements
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.4.16 tit
Syntax label operation tit operand
["string"]
Functional description
This directive specifies that the string coded as its operand is to be output as the header of the list file.
Typically the string is written with the program name, function, author, version, company, date, etc.
Operand coding rules
The operand is written with any string enclosed by double quotation marks ("). A double quotation mark itself cannot be included in the string.
Usage example
Below is an example use of the tit directive.
*** TEST PROGRAM ***
Loc Object Line
000000 54
1
2
3
4
TIT.LST
Page 1
Source tit dc end
“*** TEST PROGRAM***
0x54
Writing Directive Statements 175
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.4.17 xlistoff, xliston
Syntax label
[name]
.
.
.
operation xlistoff xliston operand
Functional description
The xlistoff and xliston directives are used in pairs. Statements from the xlistoff directive until the xliston directive will not be output to the list file. These directives are used when you do not want to output an already debugged program to the list file.
NOTE: The xlistoff and xliston directives themselves are not output.
Only output to the list file will be suppressed. Output of object code will not be suppressed at all.
Operand coding rules
These directives take no operand.
Usage example
Below is an example use of the xlistoff and xliston directives. The range from xlistoff to xliston will be suppressed.
_CODE main section mov xlistoff mov xliston mov end
CODE, PUBLIC, 2
0x11, D0
0x22, D0
0x33, D0
176 Writing Directive Statements
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.4.18 funcinfo
Syntax label operation function_namefuncinfo where operand label_name, expression, register list expression: Stack frame size
Functional description
This directive provides additional information about a function name specified as the operand to a call instruction. The call instruction branches to the function after saving registers to the stack and setting up the stack frame. To use call instructions, the program must define the stack frame size and the registers to be saved using a special format in the function’s declaration section. This special format takes the form of the funcinfo directive.l
The linker uses the specified stack size and register list to automatically set up the proper calling sequences for calls to the function.
Operand coding rules
The label_name gives the branch target used by instructions other than the call instruction--the call instruction, for example. This label_name is necessary even if no other instructions call it. In that case, assign a label to any empty statement immediately preceding the funcinfo directive and use the name of that label. The label_name must be defined prior to the funcinfo directive. Otherwise, an error results.
The expression gives the size of the stack frame used by the function. It must evaluate to a value between 0 and255. A value outside this range results in an error. The register list gives a list of registers to be saved to the stack before entering the function proper. Enclose the list in square brackets ([ ]) and separate the registers in the list with commas. The registers that can appear in the list are D2, D3, A2,
A3 and OTHER, where OTHER indicates D0, D1, A0, A1, MDR, LIR. A register specification other than these five results in an error.
NOTE: When writing directive statements in between the function and label_name, it may not link properly or it may create a bad execution format.
NOTE: Optimization can be performed for the instructions between label_name and the function name. For details, see Chapter 4 “Optimization Functions” Section 4.3
“Usage Examples”, “Optimization of function calls”.
Directive Specification Rules
The funcinfo directive must always define a branch target label for use with the call instruction.
Writing Directive Statements 177
Chapter 9 Writing Machine Language Instructions and Directive Statements
Usage Example
The following gives an example of funcinfo usage.
_TEXT
_TEXT
_func
_0func global section
: call
: global section movm add funcinfo
:
: ret
_0func
CODE, PUBLIC, 1
_0func
_0func, _func
CODE, PUBLIC, 1
[D2], (SP)
-4, SP
_func, 8, [D2]
NOTE: The ret and retf instructions free the stack frame and restore registers from the stack.
The assembler bases this code on the information provided by the funcinfo directive. For this reason, the ret and retf instructions cannot precede the funcinfo directive.
178 Writing Directive Statements
Chapter 9 Writing Machine Language Instructions and Directive Statements
9.4.19 assign
Syntax label name operation assign operand expression
Functional description
This directive defines the name to be the value of the expression coded in the operand. When that name is coded in the operand of machine language instructions or directive instructions, the assembler will refer the name’s value.
Operand coding rules
The expression coded in the operand must result in the attribute abs (absolute).
Refer to Chapter 8, “Writing Source Statements”, section 8.7, “Expressions”, section 8.7.4, “Expression
Attributes”, regarding attributes of expression.
Names defined with the assign directive can be defined again with the assign directive.
Names defined with the assign directive cannot be declared external references or external declarations.
No memory ares is reserved when an assign directive statement is executed.
Usage examples
The example below is a use of the assign directive.
Loc
00000000 assign.lst Page 1
*** PanaX Series MN1030 Cross Assembler ***
Object
8001
Line
1
2
3
Source
_TEXT
NUM section assign 0x01 mov
CODE, PUBLIC, 1
NUM, D0
00000002 8002
4
5
6
NUM assign mov
0x02
NUM, D0
NOTE: If a name defined with this directive is used, you must define the value before the statement.
Writing Directive Statements 179
Chapter 9 Writing Machine Language Instructions and Directive Statements
180 Writing Directive Statements
Скачать
Реклама