Panasonic MN1030 User Manual

Page 1
MICROCOMPUTER MN1030
MN1030 Series Cross Assembler User’s Manual
Pub.No.13110-120E
Page 2
Page 3
PanaXSeries is a trademark of Matsushita Electric Industrial Co., Ltd. Sun and Sun OS are registered trademarks of Sun Microsystems Inc. of the United States. MS-DOS is a registered trademark of Microsoft Corporation of the United States. VZ Editor is a registered trademark of Village Center, Inc. PC/AT is a registered trademark of the International Business Machines Corporation of the United States. UNIX is a registered trademark licensed by X/Open Co., Ltd. in the United States and/or other countries. MIFES is a trademark of Megasoft, Inc. All other corporation names, logotype and product names written in this book are trademarks or registered trademarks of their corresponding corporations.
Request for your special attention and precautions in using the technical information
and semiconductors described in this book
(1) An export permit needs to be obtained from the competent authorities of the Japanese Government if any of
the products or technologies described in this book and controlled under the "Foreign Exchange and Foreign Trade Law" is to be exported or taken out of Japan.
(2) The technical information described in this book is limited to showing representative characteris tics and
applied circuits examples of the products. It neither warrants non-infringement of intellectual property right or any other rights owned by our company or a third party, nor grants any license.
(3) We are not liable for the infringement of rights owned by a third party arising out of the use of the product or
technologies as described in this book.
(4) The products described in this book are intended to be used for standard applications or general electronic
equipment (such as office equipment, communications equipment, measuring instruments and hou seh old appliances). Consult our sales staff in advance for information on the following applications:
• Special applications (such as for airplanes, aerospace, automobiles, traffic control equipment, combustion equipment, life support systems and safety devices) in which exceptional quality and reliability are required, or if the failure or malfunction of the products may directly jeopardize life or harm the human body.
• Any applications other than the standard applications intended.
(5) The products and product specifications described in this book are subject to change without notice for
modification and/or improvement. At the final stage of your design, purchasing, or use of the products, therefore, ask for the most up-to-date Product Standards in advance to make sure that the latest specifications satisfy your requirements.
(6) When designing your equipment, comply with the guaranteed values, in particular those of maximum rating,
the range of operating power supply voltage, and heat radiation characteristics. Otherwise, we will not be liable for any defect which may arise later in your equipment. Even when the products are used within the guaranteed values, take into the consideration of incidence of break down and failure mode, possible to occur to semiconductor products. Measures on the systems such as redundant design, arresting the spread of fire or preventing glitch are recommended in order to prevent physical injury, fire, social damages, for example, by using the products.
(7) When using products for which damp-proof packing is required, observe the conditions (including shelf life
and amount of time let standing of unsealed items) agreed upon when specification sheets are individually exchanged.
(8) This book may be not reprinted or reproduced whether wholly or partially, without the prior written
permission of Matsushita Electric Industrial Co., Ltd.
If you have any inquiries or questions about this book or our semiconductors, please contact one of our sales offices listed at the back of this book.
Page 4

About This Manual

This manual describes the functions and operation of the cross assembler for this series of microcomputers.
• Manual Features
Chapters on installation, program development flow, and introductory operati on are provided, so first-time users can quickly get an overview and easily master operation.
Optimization, a special feature of the cross assembler, is explained in its own chapter.
Explanations of how to operate the assembler and lin ker and how to write programs are made mostly through the use of examples.
Syntax, usage notes, and examples are given for each assembler directive, assembler control statement, and macro control statement.
Use of the library manager, a tool for managing library files, is also explained.
For users of engineering workstations (EWS), a separate chapter describes differences from the MS-DOS version.
Chapters provides listings of machine-language instructions and error messages, as well as sample programs that demonstrate usage.
• Reference Techniques
This document supports four techniques for quickly finding the required information.
1. Use the index at the front of the document to find the beginnings of chapters.
2. Use the table of contents at the front of the document to find subsection headings.
3. The chapter name and the subsection heading are listed at the top and bottom edges, respectively, on each page. Thus the contents of each page can be seen at a glance.
4. Use the index at the end of the document to find technical terms.
< About This Manual 1 >
Page 5
• How to read
Chapter 1 Installation
1.3.4 Environment Settings
Heading
Before using the Cross-Assembler, verify or change the following two les.
CONFIG.SYS
If FILES and BUFFERS specications do not already exist in CONFIG.SYS, then you must add them. If they do already exist, then check their settings, and change them if necessary.
FILES=20 BUFFERS=20
NOTE: Be sure to make these settings. If the assembler is started without them, then
the error message "bad tmpbss(w)" will be output and processing will stop. This means that the number of les that can be opened simultaneously is insufficient.
Terminology: CONFIG.SYS
This is the le that sets the MS-DOS operating environment. FILES specifies the number of les that can be read and written simultaneously. BUFFERS species the size of memory used for reading/writing disks.
Supplementary explanation
Program example
Usage note
Installing PC Version
14
Heading
Chapter titles are shown here on each page, so the reader can get a quick idea of contents while flipping through the pages.
Program example
These are actual examples of command options and instructions used by the assembler. First­time users should refer to these examples when trying to use the assembler.
Usage note
These give important information. Usage note provide cautions about usage, so they should always be read.
Supplementary explanation
These are hints and terminology definitions that can help the reader use the assembler.
<About This Manual 2 >
Page 6
• Related Manuals
The following related manuals are available. Please contact our sales representative for more details.
MN1030/MN103S Series Instruction Manual
<Describes the instruction set>
MN1030 Series C Compiler User's Manual: Usage Guide
<Describes the installation, the commands, and options of the C Compiler>
MN1030/MN103S/MN103E Series C Compiler User's Manual: Language Description
<Describes the syntax of the C Compiler>
MN1030/MN103S/MN103E Series C Compiler User's Manual: Library Reference
<Describes the standard library of the C Compiler>
MN1030 Series C Source Code Debugger for Windows® User's Manual
<Describes the use of the C source code debugger for Windows®>
MN1030/MN103S/MN103E Series Onboard Debug Unit Setup Manual
<Describes the connection of the Debug Unit and explains about initial settings of the Onboard Debugger>
MN1030/MN103S Series Installation Manual
<Describes the installation of the C compiler, cross-assembler and C source code debugger and the procedure for bringing up the in-circuit emulator>
< About This Manual 3 >
Page 7
0
Chapter 1 Getting Started Chapter 2 Program Development Flow Chapter 3 Introduction to Operation Chapter 4 Optimization Chapter 5 Using Assembler Chapter 6 Using Linker Chapter 7 Types of Source Statements Chapter 8 Writing Source Statements
Chapter 9 Writing Machine Language Instruction
Statements and Directive Statements
Chapter 10 Writing Assembler Control Statements Chapter 11 Writing Macro Control Statements
1 2 3 4 5
6 7 8 9
10
11
Chapter 12 List of Machine Language Instructions Chapter 13 Error Messages Chapter 14 Reading List Files Chapter 15 Using Library Manager Chapter 16 Notes on Operating Environment Chapter 17 Appendix
12 13 14 15 16 17
index
Page 8

Table of Contents

Chapter 1 Getting Started
1.1 Purpose of This Chapter............................................................................................................................. 2
1.2 Operating Environment................................................................................................................. ............. 3
1.3 File Organization........................................................................................................................ ................ 4
1.4 Installation.................................................................................................................................. ................ 5
1.5 Setup...................................................................................................................................................... ..... 6
1.6 File Conversion Utility............................................................................................................................. 10
Chapter 2 Program Development Flow
2.1 Purpose of This Chapter........................................................................................................................... 14
2.2 Program Development Flow .................................. .......................................................................... ........ 15
2.3 Programming with Assembler....................................................................................................... ........... 17
Chapter 3 Introduction to Operation
3.1 Purpose of This Chapter........................................................................................................................... 22
3.2 Files Used by Assembler and Linker....................................................................................................... 23
3.3 Basic Operation of Assembler and Linker............................................................................................... 25
3.4 Assembling and Linking Multiple Sections............................................................................................. 30
3.5 Conditional Assembly and Linking ...................................................... ................................................... 38
Chapter 4 Optimization
4.1 Purpose of This Chapter........................................................................................................................... 44
4.2 Rules of Usage .............................................................................................................................. ........... 45
4.3 Usage Example......................................................................................................................................... 46
Chapter 5 Using Assembler
5.1 Purpose of This Chapter........................................................................................................................... 60
5.2 Starting Assembler................................................................................................................................ ... 61
5.3 Command Options ................................................................................................................................... 63
5.3.1 Output File Options........................................................................................................................ 64
5.3.2 Error Message Options................................................................................................................... 70
5.3.3 Preprocessor Options ............................................................................................................. .. ...... 76
5.3.4 Program Generation Options.......................................................................................................... 78
5.3.5 Other Options................................................................................................................................. 80
5.4 Operation Examples................................................................................................................................. 81
Chapter 6 Using Linker
6.1 Purpose of This Chapter........................................................................................................................... 84
< 1 TOC >
Page 9
6.2 Starting Linker......................................................................................................................................... 85
6.3 Command Options................................................................................................................................... 88
6.3.1 Output File Options ....................................................................................................................... 89
6.3.2 Error Message Options .................................................................................................................. 91
6.3.3 Program Generation Options......................................................................................................... 97
6.3.4 Library File Options.............................................................................................. ....................... 103
6.3.5 Other Options............................................................................................................................... 105
6.4 Instruction RAM Support ............................................................................................................. ......... 107
6.4.1 Structure of IRAM Support Executable File ............................................................................... 108
6.4.2 IRAM Support Options................................................................................................................ 111
6.4.3 Operation Examples..................................................................................................................... 114
Chapter 7 Types of Source Statements
7.1 Purpose of This Chapter ........................................................................................................................ 118
7.2 Program Format..................................................................................................................................... 119
7.3 Machine Language Instruction Statements and Directive Statements................................................... 121
7.4 Assembler Control Statements................................................................................................... ............ 122
7.5 Macro Control Statements.................................................................................................................... . 123
7.6 Comment Statements............................................................................................................................. 124
7.7 Blank Statements ................................................................................................................................... 125
Chapter 8 Writing Source Statements
8.1 Purpose of This Chapter ........................................................................................................................ 128
8.2 Permitted Characters.............................................................................................................................. 129
8.3 Numbers.................................................................................................................................. ............... 130
8.4 Character Constants........................................................................................................... .................... 133
8.5 Address Constants................................................................................................................................. . 135
8.6 Location Counter ................................................................................................................................... 136
8.7 Expressions............................................................................................................................................ 137
8.7.1 Operators...................................................................................................................................... 138
8.7.2 Expression Evaluation ................................................................................................................. 140
8.7.3 Expression Syntax........................................................................................................................ 141
8.7.4 Expression Attributes................................................................................................................... 142
8.8 Reserved Words................................................................................................................. .................... 144
Chapter 9 Writing Machine Language Instruction Statements and
Directive Statements
9.1 Purpose of This Chapter ........................................................................................................................ 146
9.2 Instruction Statement Fields .................................................................................................................. 147
9.2.1 Writing Label Field............................................................................................................ ......... 148
9.2.2 Writing Operation Field............................................................................................................... 149
9.2.3 Writing Operand Field................................................................................................................. 150
9.2.4 Writing Comment Field............................................................................................................... 151
9.3 Writing Machine Language Instruction Statements .............................................................................. 152
9.4 Writing Directive Statements................................................................................................................. 153
9.4.1 section.......................................................................................................................................... 154
9.4.2 align ............................................................................................................................................ . 156
9.4.3 end............................................................................................................................................... . 158
< TOC 2 >
Page 10
9.4.4 listoff, liston ................................................................................................................................. 159
9.4.5 notation......................................................................................................................................... 160
9.4.6 org ................................................................................................................................................ 162
9.4.7 opt................................................................................................................................................. 163
9.4.8 page.............................................................................................................................................. 164
9.4.9 radix.............................................................................................................................................. 165
9.4.10 dc................................................................................................................................................ 166
9.4.11 ds................................................................................................................................................ 167
9.4.12 dw............................................................................................................................................... 169
9.4.13 dd................................................................................................................................................ 170
9.4.14 equ.............................................................................................................................................. 171
9.4.15 global.......................................................................................................................................... 173
9.4.16 tit ................................................................................................................................................ 175
9.4.17 xlistoff, xliston ........................................................................................................................... 176
9.4.18 funcinfo...................................................................................................................................... 177
9.4.19 assign.......................................................................................................................................... 179
Chapter 10 Writing Assembler Control Statements
10.1 Purpose of This Chapter....................................................................................................................... 182
10.2 File Inclusion........................................................................................................................................ 183
10.2.1 #include...................................................................................................................................... 184
10.3 Identifier Definement........................................................................................................................... 186
10.3.1 #define........................................................................................................................................ 187
10.3.2 #undef......................................................................................................................................... 188
10.4 Conditional Assembly.......................................................................................................................... 189
10.4.1 #ifdef, #ifndef............................................................................................................................. 191
10.4.2 #if, #ifn....................................................................................................................................... 193
10.4.3 #ifeq, #ifneq ............................................................................................................................... 195
10.4.4 #iflt, #ifle.................................................................................................................................... 198
10.4.5 #ifgt, #ifge.................................................................................................................................. 200
10.4.6 #ifb, #ifnb.............................................................. ..................................................................... 202
Chapter 11 Writing Macro Control Statements
11.1 Purpose of This Chapter....................................................................................................................... 206
11.2 Macro Definitions (macro, endm) ........................................................................................................ 207
11.3 Macro Calls and Expansion ................................................................................................................. 209
11.4 Macro Operators................................................................................................................................... 211
11.5 Local Symbol Declaration (local)........................................................................................................ 213
11.6 Forced Termination of Macro Expansion (exitm) ............................................................................... 215
11.7 Purging Macro Definitions (purge)...................................................................................................... 217
11.8 rept........................................................................................................................................................ 218
11.9 irp ......................................................................................................................................................... 220
11.10 irpc...................................................................................................................................................... 222
Chapter 12 List of Machine Language Instructions
12.1 Purpose of This Chapter....................................................................................................................... 226
12.2 Addressing Modes................................................................................................................................ 227
12.3 List of Machine Language Instructions................................................................................................ 231
< 3 TOC >
Page 11
12.3.1 Data Move Instructions........................................................................................................... ... 232
12.3.2 Arithmetic Instructions.............................................................................................................. 237
12.3.3 Logical Instructions ................................................................................................................... 239
12.3.4 Bit Manipulation Instructions.................................................................................................... 241
12.3.5 Branching Instructions............................................................................................................... 243
12.3.6 User-Defined Instructions........................................................................................... ............... 247
12.3.7 Other Instructions ............................................................................................................. ......... 248
Chapter 13 Error Messages
13.1 Purpose of This Chapter ....................................................................................................... ............... 250
13.2 Assembler Errors ................................................................................................................................. 251
13.2.1 Warning Messages..................................................................................................................... 252
13.2.2 Error Messages ........................................................................................................... ............... 254
13.2.3 Fatal Error Messages ................................................................................................................. 257
13.3 Linker Errors............................................................................................................................ ............ 258
13.3.1 Warning Messages..................................................................................................................... 259
13.3.2 Error Messages ........................................................................................................... ............... 260
13.3.3 Fatal Error Messages ................................................................................................................. 262
Chapter 14 Readinig List Files
14.1 Purpose of This Chapter ....................................................................................................... ............... 266
14.2 Reading List Files............................................................................................................... ................. 267
14.2.1 Output Format of Machine Language Code.............................................................................. 268
14.2.2 Symbol Table............................................................................................................................. 271
Chapter 15 Using Library Manager
15.1 Purpose of This Chapter ....................................................................................................... ............... 274
15.2 Starting Library Manager...................................................................................................... ............... 275
15.3 Command Options............................................................................................................................... 276
15.3.1 Error Message Options ............................................................................................... ............... 276
15.3.2 Program Generation Options..................................................................................................... 282
15.3.3 Functional Options..................................................................................................................... 284
15.3.4 Other Options................................................................................................................. ............ 290
15.4 Error Messages .................................................................................................................................... 292
15.4.1 Warning Messages..................................................................................................................... 293
15.4.2 Error Messages ........................................................................................................... ............... 294
15.4.3 Fatal Error Messages ................................................................................................................. 296
Chapter 16 Notes on Operating Environment
16.1 Purpose of This Chapter ....................................................................................................... ............... 298
16.2 Personal Computer Versions ............................................................................................................ ... 299
16.2.1 Operating Environment..................................................................................................... ......... 300
16.2.2 Files............................................................................................................................................ 301
16.2.3 Installation ................................................................................................................ ................. 302
16.2.4 Environment Settings................................................................................................................. 303
16.2.5 Differences From Workstation Versions................................................................................... 305
< TOC 4 >
Page 12
16.2.6 Error Correction Using Tag Jumps............................................................................................ 306
Chapter 17 Appendix
17.1 Numeric Restrictions............................................................................................................................ 310
17.2 List of Command Options.................................................................................................................... 311
17.2.1 List of Assembler Command Options........................................................................................ 312
17.2.2 List of Linker Command Options.............................................................................................. 315
17.3 List of Assembler Directives................................................................................................................ 318
17.4 List of Assembler Control Statements ................................................................................................. 321
< 5 TOC >
Page 13

Chapter 1 Getting Started

1
Page 14
Chapter 1 Getting Started

1.1 Purpose of This Chapter

This chapter describes the operating environment for this system and the usage of the file conversion tool.
2 Purpose of This Chapter
Page 15

1.2 Operating Environment

This system runs on the following workstations, personal computers and compatibles.
Host machine Operating system Version of OS
Sun/Sparc Solaris 2.6 or later
PC/AT Windows 98/Me/2000/XP
DOS/V Windows 98/Me/2000/XP
For the PC/AT and compatibles, because of such differences as the ability to display Japanese, this Manual indicates a machine running the English-only operating system as a PC/AT and one running the Japanese operating system as a DOS/V machine.
Refer to the Release Notes for other restrictions.
Chapter 1 Getting Started
Operating Environment 3
Page 16
Chapter 1 Getting Started

1.3 File Organization

The installation media for this system contain the following files.
as103 (assembler)
as103 is the assembler. For a description, see Chapter 5 "Using Assembler."
ld103 (linker)
ld103 is the linker. For a description, see Chapter 6 "Using Linker."
slib103 (library manager)
slib103 is the library manager, a utility for creating library files. For a description, see Chapter 15 "Using Library Manager."
excv103 (file conversion utility)
This utility converts an executable produced by the linker into a file in Motorola S format, Intel HEX format, or Matsushita format.
In addition to the above files, the installation media may contain a README or README.DOC file containing late-breaking news missing from this Manual. Please read this file carefully before proceeding.
4 File Organization
Page 17

1.4 Installation

For the installation media, installation procedures, and notes on installation, see the Installation Manual.
Chapter 1 Getting Started
Installation 5
Page 18
Chapter 1 Getting Started

1.5 Setup

These procedures are for setting up this system when it has just been installed or for altering basic settings.
Setting command path
Unix uses the environment variable PATH when searching for executable files. Setting up this variable properly allows users to omit the directory name for commands and run them using their base names only.
If this system has been installed in /usr/local/bin, for example, adding the directory /usr/local/bin to the PATH environment variable permits the use of the command name only for the commands in this system.
Under Unix, most users initialize environment variables via a start-up file named .cshrc and located in the user's home directory. If this is the case, use an editor to modify the PATH variable setting in this start-up file.
To put the changes into effect, either log out and then log in again or use the source command to execute the contents of .cshrc.
Start-up files
The assembler and linker start by reading start-up files which contain statements for initializing start­up variables.
The assembler start-up file (.as103rc) contains statements specifying the following three items.
1. The default language and character coding scheme for messages from the assembler
2. The radix notation used for numbers
3. The default toggle switch setting for optimization
The linker start-up file (.ld103rc) contains statements specifying the following eight items.
1. The language and character coding scheme for messages from the linker
2. A toggle controlling output of debug ging information to the executable file
3. A toggle controlling output of the symbol table to the executable file
4. A toggle controlling output of DATA sections to the executable file
5. A toggle controlling output of a map fil e
6. A toggle controlling output of an executable file when there are errors
7. A library file
8. A directory searching for a library file
6 Setup
The assembler and linker search directories for these start-up files in the following order: the current directory, the user's home directory, and the directory containing the executable. If they find such a file, they use the contents to initialize their starting parameters. Otherwise, they set the parameters to their default values. These default values are given in the section "Start-up file format."
Page 19
NOTE: Note that the command line is preceded when specifying the option which can
Start-up file format
The start-up files contain statements using the following format.
keyword parameter
The first field is a keyword giving the name of the start-up parameter. The second field specifies the value to assign to that parameter. The two fields must be separated by at least one tab or space.
A sharp (#) may be used to incorporate comments into these start-up files. The assembler and linker then ignore all text from the sharp through to the end of the line.
Chapter 1 Getting Started
be set in an environmental setting file with the command line at starting the assembler and the linker. Refer to the Chapter 5 “Using Assembler” for the assembler and to the Chapter 6 “Using Linker” for the linker. The order of precedence is as follows.
1) Specify by Command
2) Specify in Environmental setting file
NOTE: Each specification must end with a carriage return. In particular, make sure that
the last line ends with a carriage return. Some editors allow users to end the last line with an end-of-file mark instead of a carriage return.
NOTE: There is no way to specify multiple parameters on the same line.
Setup 7
Page 20
Chapter 1 Getting Started
The start-up file .as103rc supports the following keywords.
Keyword Description
This entry specifies the language and coding scheme for messages from the assembler. One of the parameters ENGLISH, EUC, SJIS, or JIS comes after the keyword “message” followed by a blank space. These parameters have the following meanings. message ENGLISH Outputs messages in English message EUC Outputs messages in Japanese using EUC encoding
message
message SJIS Outputs messages in Japanese using Shift JIS encoding message JIS Outputs messages in Japanese using JIS encoding The default setting depends on the host machine and operating system. Sun/Sparc ENGLISH DOS/V SJIS PC/AT ENGLISH
This entry specifies the notation used for numbers in assembly language programs. One of the parameters PANA, CLANG, or INTEL comes after the keyword “notation” followed by a blank space. These parameters have the following meanings.
notation
notation PANA Use Panasonic notation notation CLANG Use C language notation notation INTEL Use Intel notation The default setting is in extended C language format.
This entry controls optimization. Either ON or OFF of the parameters comes after the keyword O-OPTION followed by a blank space. These parameters have the following
O-OPTION
meanings. O-OPTION ON Enable optimization O-OPTION OFF Disable optimization The default setting is to disable optimization.
The start-up file .ld103rc supports the following keyboards.
Keyword Description
This entry specifies the language and coding scheme for messages from the linker. One of the parameters ENGLISH, EUC, SJIS, or JIS comes after the keyword “message” followed by a blank space. These parameters have the following meanings. message ENGLISH Outputs messages in English message EUC Outputs messages in Japanese using EUC encoding
message
message SJIS Outputs messages in Japanese using Shift JIS encoding message JIS Outputs messages in Japanese using JIS encoding The default setting depends on the host machine and operating system. Sun/Sparc ENGLISH DOS/V SJIS PC/AT ENGLISH
This entry controls the output of debugging information. Either ON or OFF of the parameters comes after the keyword g-OPTION followed by a blank space. These
g-OPTION
parameters have the following meanings. g-OPTION ON Enable output of debugging information g-OPTION OFF Disable output of debugging information The default setting is to disable output of debugging information.
8 Setup
Page 21
Keyword Description
This entry controls the output of debugging of the symbol table to the executable file. Either ON or OFF of the parameters comes after the keyword En-OPTION followed by a
En-OPTION
blank space. These parameters have the following meanings. En-OPTION ON Disable output of the symbol table to the executable file. En-OPTION OFF Enable output of the symbol table to the executable file. The default setting is to disable output of the symbol table to the executable file.
This entry controls the output of DATA sections to the executable file. Either ON or OFF of the parameters comes after the keyword Ed-OPTION followed by a blank space. These
Ed-OPTION
parameters have the following meanings. Ed-OPTION ON Enable output of DATA section to the executable file. O-OPTION OFF Disable output of DATA section to the executable file. The default setting is to disable output of DATA section to the executable file.
This entry controls the output of the map file. Either ON or OFF of the parameters comes after the keyword m-OPTION followed by a blank space. These parameters have the
m-OPTION
following meanings. m-OPTION ON Enable output of the map file. m-OPTION OFF Disable output of the map file. The default setting is to disable output of the map file.
Chapter 1 Getting Started
r-OPTION
stdlib
libdir
This entry controls the output of the executable file when there are assembler errors. Either ON or OFF of the parameters comes after the keyword r-OPTION followed by a blank space. These parameters have the following meanings. r-OPTION ON Enable output of the executable file when there are assembler errors. r-OPTION OFF Disable output of the executable file when there are assembler errors. The default setting is to disable output of executable file when there are assembler errors.
This entry specifies the library file. The library file name comes after the keyword stdlib followed by a blank space. Two or more stdlib descriptions are allowed. The default setting is no specification.
This entry specifies the directory for searching library files. The library file name comes after the keyword libdir followed by a blank space. Two or more libdir descriptions are allowed. The default setting is no specification.
Setup 9
Page 22
Chapter 1 Getting Started

1.6 File Conversion Utility

This file conversion utility converts an EX format file produced by the linker into a file in Intel HEX format, or Motorola S format.
General command format
The general command format used to start the file conversion utility is shown below.
excv103 [options] EX format file name
Contents of brackets [ ]may be omitted.
Options
Option Description
-j Displays error and warning messages in Japanese. *1
-e Displays error and warning messages in English. *2
-h Displays help information regarding file conversion utility options to the screen.
Perform conversion using a work file during execution. This enables a large amount of
-w
-i Output the execution file in Intel HEX format.
-S3 Output the execution file in Motorola S3 format.
-S2 Output the execution file in Motorola S2 format. S1 Output the execution file in Motorola S1 format.
-ofile Specify the file name to output
-p No padding.
-P Padding.
-R start address, end address
-A start address
data to be converted even if the personal computer has little memory. However, conversion speed will be slower.
Converts the addresses within the specified range. If omitting the end address, a conversion is performed until the last address of the execution module.
Perform conversion for the starting address of EX format file into the specified address.
10 File Conversion Utility
*1 Option for UNIX version. *2 Option for DOS/V version
Page 23
Default specification
See the default settings for the following operations.
Operation Default Setting
Chapter 1 Getting Started
Message to output Conversion method Not with a work file
Output format Intel HEX format Padding No padding Output file name The same file name as EX format file but with “.hex” or “.rom” extensions. Conversion range From the start to the end address in EX format file.
UNIX and PC/AT versions: English DOS/V version: Japanese
Rules of output file name
Based on input file name or the file name specified with “o” option, change the extension. It is an output file name. The rules are different from each option specified.
Option Extension i .hex S3, S2, S1 .mot default .hex
In addition, a file with “.rom” extension is output with them. The file contains its tool information.
File Conversion Utility 11
Page 24
Chapter 1 Getting Started
Example of specifying options
1. Specify the range of data conversion. (-R)
excv103 -R1000, 1020 sample.ex
Converts the data between the address 1000 and the address 1020 in the file of sample.ex.
2. Specify the start address upon format conversion. (-A)
excv103 -A1000 sample.ex
In the file of sample.ex, the information of start address specified when linking has been set. It will be needed when changing the start address for the format conversion. The example above, conversion has performed as the start address for the address 1000.
excv103 -A4000, 8000 -A1000 sample.ex
Converts the data between the address 4000 and the address 8000 in the file of sample.ex into the data of the address 1000.
3. Convert into a file in Intel HEX format.
excv103 -i sample.ex
Perform conversion a file into a file in Intel HEX format.
4. Convert into a file in Motorola S format.
excv103 -S1 sample.ex excv103 -S2 sample.ex excv103 -S3 sample.ex
Perform conversion a file into a file in Motorola format.
-S1: 16-bit address format
-S2: 24-bit address format
-S3: 32-bit address format
5. Convert without padding.
excv103 -p sample.ex
Do not pad (0xff) when converting.
6. Convert with padding.
excv103 -P sample.ex
Do pad (0xff) when converting.
12 File Conversion Utility
Page 25

Chapter 2 Program Development Flow

2
Page 26
Chapter 2 Program Development Flow

2.1 Purpose of This Chapter

Programs can be developed with a compiler or an assembler.
Currently most program development is done with a compiler, but an assembler is where compact code generation or faster processing speed is required.
This chapter gives an overview of development with the assembler, and explains the flow of development through completion.
14 Purpose of This Chapter
Page 27

2.2 Program Development Flow

Main development flow
The microcomputers are used in such diverse applications as AV equipment, household electronics, information equipment, automobiles, robots, portable phones, computer peripherals, etc. Programs developed with the Cross-Assembler are ultimately incorporated into these products.
The software is developed using a source code debugger running the software on a target board which differs from the operating environment for the final application.
Assembler and compiler
Both the assembler and C compiler can be used to develop programs for the microcomputers. Compared to assembly language, C language is a more productive language. Programs code d using a high-level language also offer superior ability for documentation.
Chapter 2 Program Development Flow
On the other hand, microcomputer operations can be directly coded by programming with assembly language. Compared to high-level languages, programs can be created with more compact code size, less redundancy, and faster processing.
Given the features of both languages, the main body of a program can be coded using C language, while parts that require fast processing can be coded using assembly language.
When developing a program, the programmer must first consider which language to use, program structure, processing speed required to meet the target performance of the end product, ROM size of the device, and several other related factors.
Program Development Flow 15
Page 28
Chapter 2 Program Development Flow
Source code debugger
The software developed on a workstation or personal computer must be checked using a hardware environment similar to that used by the final product.
Nearly all of this series microcomputers will ultimately be incorporated wi thi n end products. Therefore, program debugging must also be performed under the same conditions as the end product. This is why a source code debugger and in-circuit emulator are provided.
The probe of the in-circuit emulator can operate in place of the microcomputer by connecting it through the microcomputer socket in the product.
The source code debugger is a program for controlling the in-circuit emulator's hardware. The debugger downloads the application developed on a workstation or personal computer to the emulator's memory to create an environment in which the application runs as if it were in the microcomputer's ROM. It can start program execution as the address of any source statement, and can temporarily stop execution. Also, when execution is stopped, the source code debugger can display values of internal registers and memory and can be used to verify desired operation of programs by changing those values. It also enables more detailed operation checks with step operation, whereby execution proceeds one instruction at a time.
Using this development environment, the developer can prove programs in the same state as when finally incorporated into the microprocessor.
16 Program Development Flow
Page 29

2.3 Programming with Assembler

Before creating programs using the assembler, you must understand the following items.
Required knowledge
Machine-language instructions
Device operation
Editor use
C compiler use
Assembler and linker use (in this manual)
Debugger use
Program development is an iterative process of editing, assembling, linking, and debugging many times until finished. Therefore, you should as much as possible automate assembler and linker commands, debugger calls, and error correction.
Chapter 2 Program Development Flow
MAKE
When a program is divided into multiple files for joint development efforts by several programmers, a control system must be created for assembly and linking without error.
If this is not done, an old undebugged program could be linked within the iterative development process.
The solution lies with the following program which runs on the workstation or personal computer.
•MAKE
With MAKE the programmer defines the dependency relationships of the files needed to generate the final executable file and list files. Afterwards MAKE will automatically assemble and link only those files that have been modified.
Program format
The Cross-Assembler utilizes a program format called section address format. Section address format specifies the start addresses of programs for each section linked. Even when the
program is divided between multiple files, or when a file is divided into multiple sections, identical sections are linked together with the same attributes. Therefore, the programmer must create programs such that addresses do not overlap.
[Reference: Chapter 6, "Using Linker", for details]
Programming with Assembler 17
Page 30
Chapter 2 Program Development Flow
Programming style
It is important to use a consistent style for program coding from start to finish. When several people are to create a program, they should meet in advance to decide on a common style.
You should consider the following points regarding the fixed style of the Cross Assembler.
Header files Constants and variables used in all files and define identifiers used in common should be gathered into a single header file. As a result, changes can be made at just one location in the header file.
Library files Subroutine programs frequently used by different files should be gathered by function as library files to make programs easier to use.
Declaration position global directives Use one position for global directive declarations. The global directive can be declared anywhere within a program, but confusion will result if the declaration positions differ across source files.
Unify radix and notation directives
Comment statements
Optimization
This Series' optimizations apply to unconditional branches, data transfer instructions, arithmetic instructions, logical instructions, bit manipulatio n instructions, and user-defined instructions.
Unconditional branches that undergo optimization
Data transfer, arithmetic, logical, bit manipulation, and user-defined instructions t hat undergo
Coding is not a simple task if the programmer must always select the optimal instruction from the above instructions. In particular, it is nearly impossible to select the optimal instructions when coding a program divided between files in section format.
The optimization functions provide a solution to these problems. The assembler and linker use them to produce the optimal code no matter what the source code.
Choose a common default radix for coding numbers, constant values, strings, etc.
Comments reveal program algorithms and processing details within a program. Choose a common format for coding comment statements.
optimization
The assembler evaluates the source statement notation. It evaluates the immediate data, memory specifications, and displacement data appearing as operands to a data transfer, arithmetic, logical, bit manipulation, and user-defined instructions and selects the shortest version of the instruction.
The assembler also examines unconditional branches, choosing the shortest versions for the CALL, CALLS, JMP, and JSR instructions.
The linker evaluates instructions that were the object of optimization, and selects the optimal codes. As a result, the programmer must be aware that the generated code will differ from the source
statements coded in the list file.
18 Programming with Assembler
Page 31
Conditional assembly
If a program for product A is to be created by partially modifying a program for product B, both can be combined into a single program by using conditional assembler control instru ct ions.
Conditional assembly is done by defining a single symbol at the start of the program using a define control directive.
Here is an example.
#define TYPE A
Using TYPE and conditional assembler control directives to process different parts of the program, the programmer writes code in the format below.
. . . TYPE Program of product A
#else
Program of product B
#endif
. . .
Chapter 2 Program Development Flow
TYPE has been defined with define, so in this case the program for product A will be assembled. If the statement
is omitted, the program for product B will be assembled. By using conditional assembler control directives in this manner, different versions of programs can be
managed in a single source file.
Macros
Macros are an important function of the assembler. A macro assigns a name to a process, thereby simplifying the coding of that process. By assigning an appropriate macro name to a block of multiple machine language instructions, the programmer can create custom instructions.
Debugging
When performing final program debugging, the programmer must verify whether the intended operations are being performed or not. A source code debugger is provided for this. The programmer uses the debugger to download generated and linked object code and verify operation.
The g option of the assembler and linker generates information that allows the debugger to work with symbols. This allows symbols to be used for specifying debugger start addresses, breakpoint settings, memory references and changes, etc.
#define TYPE A
[Reference: Chapter 10, "Writing Assembler Control Statements", for details]
Programming with Assembler 19
Page 32
Chapter 2 Program Development Flow
20 Programming with Assembler
Page 33

Chapter 3 Introduction to Operation

3
Page 34
Chapter 3 Introduction to Operation

3.1 Purpose of This Chapter

Many options are provided with the Cross-Assembler and Linker, but you can use the assembler and linker without knowing all of them. This chapter explains how to use the most useful options while demonstrating actual operation.
This chapter first uses an example to show how to run the assembler and linker. Next, it explains assembler and linker use when assembler control statements and macro instructions are included for high-level operations.
After reading this chapter once through and trying actual operation, you will have mastered basic assembler and linker operation.
22 Purpose of This Chapter
Page 35
Chapter 3 Introduction to Operation
T

3.2 Files Used by Assembler and Linker

Figure 3-1 shows the inter-relationships of the files used by the assembler and linker.
Map file
SAMPLE.MAP
-a
Library file
SAMPLE.LIB
Source file
SANPLE.ASM
Assembler
Linker
Include file
SAMPLE.H
-l
SAMPLE.LS
Relocatable object files
SAMPLE.RF ...
List file
-m
Map file
m103.map
Executable file
m103.ex
Figure: 3-1 Files Used
The assembler inputs source files and include files, and outputs relocatable object files. Include files are not special files, but are just files that comprise parts of the source file. They are
incorporated into assembly at the location of include directives defined within source statements.
Files Used by Assembler and Linker 23
Page 36
Chapter 3 Introduction to Operation
Depending on the option specifications input for the source file and map file, a list file will be output with fully resolved addresses.
The map file is used to output a list file with fully resolved addresses. The linker inputs relocatable object files output by the assembler and, depending on option
specifications, library files. It generates an executable format file and, depending on option specifications, a map file.
Library files are collections of relocatable object files of frequently used programs and hardware interface programs. Only needed modules are specified to have the linker extract the appropriate relocatable object files from library files and load them into the executable format file. Several library files are provided, but you can maintain them or newly create them yourself. Refer to chapter 15, "Using The Library Manager", for details.
You cannot force different extensions for map files and list files. You can only specify whether or not to output these files. However, the extensions of relocatable object files and the executable format file can be changed with assembler and linker option specifications. In this case, the file specification must include the extension.
24 Files Used by Assembler and Linker
Page 37
Chapter 3 Introduction to Operation

3.3 Basic Operation of Assembler and Linker

The Cross-Assembler uses a section address format, in which the start address for each section as defined with the section directive corresponds to its start address when linked. This allows the programmer to freely change the order of linking files.
The following explanation illustrates a simple example of only one section. In this example you will assemble and link two source files, program1.asm and program2.asm.
These two files have related external references and external definitions, where the subroutine of program2.asm is called from program1.asm. Therefore the final list files cannot be created just by assembling program1.asm. In this example, you will generate with the linker a map file and generate the final list files.
Create source files
First, create the source files. Using an editor, create the two programs shown below (program1.asm and program2.asm).
The contents of program1.asm are as follows.
global data_set __CODE section CODE, PUBLIC, 1 main
mov 0, A0
mov 0xff, D0
mov 0x80, D1
jsr data_set
bra main _DATA section DATA, PUBLIC, 4 data1 ds 4
end
program1.asm consists of a section called _CODE (attribute CODE, link type PUBLIC) and a section called _DATA (attribute DATA, link type PUBLIC).
Basic Operation of Assembler and Linker 25
Page 38
Chapter 3 Introduction to Operation
The contents of program2.asm are as follows.
global data_set __CODE section CODE, PUBLIC, 1 data_set
mov 0, D2 data_set_loop
cmp D1, D2
bcc data_set_end
mov D0, (A00
add 1, D2
add 2, A0
bra data_set_loop
data_set_end
rts
end
program2.asm also consists of a section called _CODE (attribute CODE, link type PUBLIC), and it makes an external declaration of data_set.
Assemble
Assemble the two programs that you created to generate relocatable object files.
This will generate two relocatable object files (program1.rf and program2.rf). List files cannot be generated at this stage. These files will be generated after linking when the relationships of external references and external definitions are resolved.
as103 program1.asm as103 program2.asm
26 Basic Operation of Assembler and Linker
Page 39
Link
Chapter 3 Introduction to Operation
Link the two relocatable object files to generate an executable format file. A map file will be generated along with the executable format file at this time.
ld103 -m -T_CODE=40000000 program1.rf program2.rf m option Option to output map file. T option Option to specify section address.
The above command line links two relocatable object files (program1.rf and program2.rf) and creates an executable file (m103.ex) and a map file (m103.map) in the current directory.
Supplemental Explanation:
The -o option is also available for specifying a different output file name and directory for the executable file. Omitting this option results in the use of the default name m103 and the extension .ex. There is no option for specifying the name of the map file. It uses the same default name as the executable file, m103, and the extension .map. The output directory is the same as that used for the executable file.
Generate final list files
After link processing is complete, generate the final list files using the map file (m103.map).
as103 -l -a m103.map program1.asm as103 -l -a m103.map program2.asm
l option Option to output a list file. a option Option to read a map file. Specify the map file name after it.
This operation will generate the final list files (program1.lst and program2.lst) in the current directory. With the above operations, you can generate an executable format file and final list files in the current
directory. You must generate the final list files using the map file after linking. This is because linking determines
the start addresses of sections following the T option for files in section address format. In addition, there may be addresses unresolved until after link processing due to forward references, optimization, etc. (Refer to chapter 4, "Optimization".)
Basic Operation of Assembler and Linker 27
Page 40
Chapter 3 Introduction to Operation
The contents of the final list file program1.lst are as follows.
program1.lst Page 1
*** PanaX Series MN1030 Cross Assembler ***
Loc Object Line Source
1 global data_set 2
3 _CODE section CODE, PUBLIC, 1 40000000 4 main 40000000 9000 5 mov 0, A0 40000002 2CFF00 6 mov 0xff, D0 40000005 2D8000 7 mov 0x80, D1 40000008 40000010 00F8FE04 8 40000014 CAF2 9 bra main
40000024 00000000 12 data1 ds 4
*** Symbol
F8FEFCFCFF0C0000
8 jsr data_set
10
11 _DATA section DATA, PUBLIC, 4
13 end
program1.lst Page 2
Table ***
40000016 T data_set 40000000 T main 40000024 D data1
28 Basic Operation of Assembler and Linker
Page 41
Chapter 3 Introduction to Operation
The contents of the final list file program2.lst are as follows.
program2.lst Page 1
*** PanaX Series MN1030 Cross Assembler ***
Loc Object Line Source
1 global data_set 2
3 _CODE section CODE, PUBLIC, 1 40000016 4 data_set 40000016 8A00 5 mov 0, D2
6 40000018 7 data_set_ loop 40000018 A6 8 cmp D1, D2 40000019 C60A 9 bcc data_set_end
10 4000001b 60 11 mov D0, (A0) 4000001c 2A01 12 add 1, D2 4000001e 2002 13 add 2, A0 40000020 CAF8 14 bra data_set_loop
15 40000022 16 data_set__ end 40000022 F0FC 17 rts
18 end
program2.lst Page 2
*** Symbol Table ***
40000016 T data_set 40000018 T data_set_ loop 40000022 T data_set_ end
Here is a simple explanation of how to read the list files. A list file shows four items of information. Source statements and machine language code
Source statements and machine language code
Symbol table
Source statements and their corresponding machine language code are further divided into Loc, Object, Line, and Source headings.
The Loc heading gives location counter values, which show execution addresses in the final list files. program1.lst starts from location 40000000 (hex.), and program2.lst starts from location 40000016 (hex.).
The Object heading shows the codes of instructions converted to machine language by the assembler. Instructions consist of one to four bytes (1 byte=8 bits), shown as two to eight hex digits. After some machine language code, the symbol 'M' will be added. The 'M' indicates an instruction that was expanded from a macro instruction.
The Line heading shows line numbers added by the assembler. The Source heading shows the source statements as coded.
Basic Operation of Assembler and Linker 29
Page 42
Chapter 3 Introduction to Operation

3.4 Assembling and Linking Multiple Sections

In section 3.3, "Basic Operation of the Assembler and Linker", source files each comprising one section were assigned to the same section as a basic example. However, normally a program will be divided into multiple sections to clearly divide programs by function and type.
The start addresses of a program in section format are set for each section during linking. Therefore, when a program divided into multiple files is developed, work can proceed without the programmer staying aware of the code size of each file. The programmer an also freely change the order in which files are linked.
The following explanation illustrates a simple example dividing two source files into sections for each routine, allocated to two sections.
Create source files
Using an editor, create the two programs shown below (program3.asm and program4.asm). The contents of program3.asm are as follows.
global main
global data_set, time_filler _CODE_00 section CODE, PUBLIC, 1 main
mov 0, A0
mov 0xff, D0
mov 0x80, D1
jsr data_set
jsr time_filler
bra main
_DATA section DATA, PUBLIC, 4 data1 ds 4
end
30 Assembling and Linking Multiple Sections
Page 43
The contents of program4.asm are as follows.
global data_set, time_filler
_CODE_01 section CODE, PUBLIC, 1 data_set
mov 0, D2
data_set_ loop
cmp D1, D2 bcc data_set_end
mov D0, (A0) add 1, D2 add 2, A0 bra data_set_loop
data_set_end
rts _CODE_00 section CODE, PUBLIC,1 time_filler
mov 0, D2 Time_filler _loop
cmp D1, D0
bcc time_filler_end
bra time_filler_loop time_filler _end
rts
end
Chapter 3 Introduction to Operation
As can be seen from the above two files, these programs are divided as follows.
main, time_filler ..._CODE_00
data_set ..._CODE_01
data1 ..._DATA
Assemble and generate list files
Next assemble the two programs. Assemble with the option for output of list files in order to see what the list file is like when final addresses are not resolved.
as103 -l -g program3.asm as103 -l -g program4.asm
g option Option to output debug information in the relocatable object file. l option Option to output list file (not normally specified at this stage before linking, but
specify it here to see intermediate values).
This will assemble the two source files (program3.asm and program4.asm) in the current directory. It will add debug information (g option) to the relocatable object files (program3.rf and program4.rf), and
Assembling and Linking Multiple Sections 31
Page 44
Chapter 3 Introduction to Operation
generate list files (program3.lst and program4.lst) respectively in the current directory (l option). Adding debug information (g option) enables symbols to be used during debugging.
Let's take a look at the list files that were created. The contents of the list file program3.lst are as follows. Note that the symbol table is not displayed.
program3.lst Page 1
*** PanaX series Series MN1030 Cross Assembler ***
Loc Object Line Source
1 global main 2 global data_set,
3
4 _CODE_00 section CODE, PUBLIC, 1 00000000 5 main 00000000 9000 6 mov 0, A0 00000002 2CFF00 7 mov 0xff, D0 00000005 2D8000 8 mov 0x80, D1 00000008 00000010 00F8FE04 9 00000014 0000001c 00F8FE04 10 00000020 CA00 +11 bra main
00000000 00000000 14 data1 ds 4
F8FEFCFCFF00000
F8FEFCFCFF000000
+9 jsr data_set
+10 jsr time_filler
12
13 _DATA section DATA, PUBLIC,4
15 end
time_filler
There is a plus sign '+' before line numbers 9 and 10. This indicates that the object code does not have final values. This is because the two functions data_set and time_filler do not exist in this program, so the call addresses will not be resolved unless linked. That further means that this list file is not the final list file.
Line number 11 also has a plus sign. This indicator warns that the line contains a symbol that is not assigned a final value until linking.
Finally, notice that the list begins from location 000000. The start addresses of section format programs are specified with the linker. Here the assembler uses relative values beginning from 000000 as location counter values.
32 Assembling and Linking Multiple Sections
Page 45
Chapter 3 Introduction to Operation
The contents of the list file program4.lst are as follows. Note that the symbol table is not displayed.
program4.lst Page 1
*** PanaX series Series MN1030 Cross Assembler ***
Loc Object Line Source
1 global data_Set, time_filler
2 global data_set, time_filler
3 _CODE_01 section CODE, PUBLIC, 1
00000000 4 data_set 00000000 8A00 5 mov 0, D2
6
00000002 7 data_set_loo
p 00000002 A6 8 cmp D1, D2 00000003 C600 +9 bcc data_set_end
10 00000005 60 11 mov D0, (A0) 00000006 2A01 12 add 1, D2 00000008 2002 13 add 2, A0 0000000a CA00 +14 bra data_set_loop
15
16 data_set_end 0000000c F0FC 17 rts 0000000c 18
19 _CODE_00
20 00000000 21 time_filler 00000000 8A00 22 mov 0, D2
23 00000002 24 time_filler_ loop 00000002 A4 25 cmp D1, D0 00000003 C600 +26 bcc time_filler_end 00000005 CA00 +27 bra time_filler_loop
28 00000007 29 Time_filler_ end 00000007 F0FC 30 rts
31 end
32
section
CODE, PUBLIC, 1
This file is defined as two sections. The addresses of the starting locations of both sections is assumed
00000000. The plus signs in lines 14 and 27 have the same meaning that they had in program3.lst--namely, that
the line contains a symbol that is not assigned a final value until linking.
Assembling and Linking Multiple Sections 33
Page 46
Chapter 3 Introduction to Operation
Link
Link the two relocatable object files to generate an executable format file. Specify the g option to add debug information to the executable format file.
A>ld103 -m -g -T_CODE_00=800000000 -T_CODE_01=80005000 pro gram 3.rf program4.rf m option Option to output map file. g option Option to add debug information to the executable format file. T option Option to specify section address.
The above command line links two relocatable object files (program3.rf and program4.rf) in the current directory, assigning the starting address 80000000 (hex.) to section _CODE_00 and the starting address 80005000 (hex.) to section _CODE_01, and creates an executable file (m103.ex) including debugging information and a map file (m103.map) in the current directory.
Parameter file during linking
The following command was input to link.
A>ld103 -m -g -T_CODE_00=800000000 -T_CODE_01=80005000 program3.rf program4.rf
Repeated input of lines like this is tedious and prone to errors. For this reason the very convenient @ option is provided with the linker. With an editor create a file PFILE (the name can be freely chosen) with the following contents.
The contents of pfile are as follows.
-m
-g
-T_CODE_00 =80000000
-T_CODE_01 =80005000 program3.rf program4.rf
This file is called a parameter file. If the @ option is specified when linking, the linker will read a parameter file, and will interpret its contents as command options for execution.
The two specifications below will be equivalent.
ld103 @PFILE ld103 -m -g -T_CODE_00=80000000 -T_CODE_01=80005000 program3.rf
program4.rf
34 Assembling and Linking Multiple Sections
Page 47
Generate final list files
After link processing is complete, generate the final list files using the map file (program3.MAP). This will show what happens to the previous '+' and 'R' marks.
as103 -l -a m103.map program3.asm as103 -l -a m103.map program4.asm
l option Option to output a list file. a option Option to use a map file.
Specify the map file name after the a option, followed by the source file name. Based on the link information written in the map file, the assembler will reassemble the source file and generate a final list file.
Let's look at the final list files with all addresses resolved. The contents of the final list file program3.lst are as follows. Note that the symbol table is not displayed.
Chapter 3 Introduction to Operation
program3.lst Page 1
*** PanaX series Series MN1030 Cross Assembler ***
Loc Object Line Source
1 global main 2 global data_set,
time_filler 3 4 _CODE_00 section CODE, PUBLIC, 1
8000000 5 main 8000000 9000 6 mov 0, A0 8000002 2CFF00 7 mov 0xff, D0 8000005 2D8000 8 mov 0x80, D1 8000008 8000010 00F8FE04 9 8000014 800001c 00F8FE04 10 8000020 CAE0 11 bra main
8000500e 00000000 14 data1 ds 4
F8FEFCFCFFF44F00
F8FEFCFCFF0C0000
9 jsr data_set
10 jsr time_filler
12 13 _DATA section DATA, PUBLIC, 4
15 end
Compare this listing file to the one with indeterminate addresses. Note how the plus signs have disappeared from lines 9-11 and how the addresses start from 80000000 (hex.), the number specified with the -T option.
Assembling and Linking Multiple Sections 35
Page 48
Chapter 3 Introduction to Operation
The contents of the final list file program4.lst are as follows. Note that the symbol table is not displayed.
program4.lst Page 1
*** PanaX series Series MN1030 Cross Assembler ***
Loc Object Line Source
1 global data_set, time_filler 2
3 _CODE_01 section CODE, PUBLIC, 1 80005000 4 data_set 80005000 8A00 5 mov 0, D2
6 80005002 7 data_set_ loop 80005002 A6 8 cmp D1, D2 80005003 C60A 9 bcc data_set_end
10 80005005 60 11 mov D0, (A0) 80005006 2A01 12 add 1, D2 80005008 2002 13 add 2, A0 8000500a CAF8 14 bra data_set_loop
15 8000500c 16 data_set_ end 8000500c F0FC 17 rts
18
19 _CODE_00 section CODE, PUBLIC,1
20 80000022 21 time_filler 80000022 8A00 22 mov 0, D2
23 80000024 24 time_filler_loop
80000024 A4 25 cmp D1, D0 80000025 C605 26 bcc time_filler_end 80000027 CA03 27 bra time_filler_loop
28 8000002a 29 time_filler_end
8000002a F0FC 30 rts
31 end
32
In this file the '+' on line numbers 14 and 27 have disappeared, and the start address of the first section _CODE_01 has been changed to address 80005000 (hex.) as specified by the T option. However, the start address of section _CODE_00 is address 80000022 (hex.). This shows that it has been linked after the same section existing in program3.
36 Assembling and Linking Multiple Sections
Page 49
program locations after linking
0
0 0
0
0 0
program locations in the executable file after linking as above are shown below.
0X0000
~~ ~~
X080000
X080016 X08001E
~~ ~~
X080200
X08020E X080211
~~ ~~
Unused
main
time_filler
Unused
data_set
data1
Unused
Chapter 3 Introduction to Operation
~~ ~~
~~ ~~
~~ ~~
Figure: 3-2 program Location
If the program contains multiple sections, it is laid out using the following rules.
Each section is assigned the starting address specified to the linker.
Sections with the same section name and section attributes are merged in the order specified to the linker--that is, in the order in which they appear in the object file names following the linker options.
Rules for joining sections
1. Join in the order in which the sections appear during linking.
2. Join sections for which both name and att rib ute match.
3. Join sections for which either name or attribute match.
For further details, see Chapter 6 "Using the Linker" Section 6.3 "Command Options" Section 6.3.3 "Program Generation Options."
Assembling and Linking Multiple Sections 37
Page 50
Chapter 3 Introduction to Operation

3.5 Conditional Assembly and Linking

The Cross-Assembler provides many assembler directives. Assembler directives are not converted directly to machine language, but are used to control how the assembler processes.
For example, during the development stage a programmer may want to include a special program only for debugging. This program must be deleted when the product is complete. That can be accomplished by editing the source file, but if that editing is spread throughout the program, mistakes will be easy to make.
It is convenient to use assembler directives in such cases. The conditions for assembly are defined at the start of the program, and programs to be assembled when the conditions are satisfied or not satisfied are written in the source file.
Create source file
Using an editor, create the program program5.asm shown below. The contents of program5.asm are as follows.
#define DEBUG * dat_set macro adr, dat
mov adr, A0 mov dat, D0 mov D0, (A0)
endm * _CODE section CODE, PUBLIC,2 main DEBUG
#ifdef
#else #endif dat_set data1, 0x22
_DATA section DATA, PUBLIC, 2 data1 dw 0 data2 dw 0
dat_set data1, 0x11
end
The operation of this program is meaningless. The program will be used instead to explain program structure as it pertains to conditional assembly.The define DEBUG on the first line selects DEBUG as a condition by defining the identifier DEBUG. In the assembly control block starting with #ifdef DEBUG on line 13, the instructions between #ifdef to #else will be assembled if DEBUG has been defined, and the instructions between #else to #endif will be assembled if DEBUG is undefined. In this example DEBUG was defined on line 1, so the instructions in the defined block will be assembled.
This program also uses a macro control directive. Lines 4 to 8 are the macro definition. The macro's name is dat_set, and it has two parameters (adr, dat).
38 Conditional Assembly and Linking
Page 51
Chapter 3 Introduction to Operation
Assemble and link
Assemble and link the program that you have created.
as103 program5.asm ld103 -m -T_CODE=400000000 program5.rf as103 -l -a m103. program5.asm
The first assembly generates the relocatable object file program5.rf. The second assembly generates the final list file program5.lst.
See the contents of the list file that was generated. The contents of the final list file program5.lst are as follows.
Note that the symbol table is not displayed.
program5.lst Page 1
*** PanaX series Series MN1030 Cross Assembler ***
Loc Object Line Source
1 #define DEBUG 2 3* M4 dat_set macro adr, dat 5 mov adr, A0 6 mov dat, D0 7 mov D0, (A0) 8 endm 9* 10 11 _CODE section CODE, PUBLIC, 1
40000000 12 main
13 #ifdef DEBUG
M14 dat_set data1, 0x11 40000000 FCDC0C000040 14+ mov data1, A0 40000006 8011 14+ mov 0x11, D0 40000008 60 14+ mov D0, (A0)
15 #else
16X dat_set data1, 0x22
17 #endif
18
19 _DATA section DATA, PUBLIC, 4 4000000C 00000000 20 data1 dd 0 40000010 00000000 21 data2 dd 0
22 end
Line number 14 extends over four lines. This indicates lines where macro expansion has been performed. An 'M' is added before the line number where the macro instruction statement is shown, and a '+' is added after the line numbers where the instruction statements from macro expansion are shown.DEBUG has been defined, so the block between #ifdef to #else was assembled. Line number 16 has an X after the line number. This indicates a statement that was not assembled because a condition was not fulfilled.
Conditional Assembly and Linking 39
Page 52
Chapter 3 Introduction to Operation
Select false condition, assemble, and link
Make the define source statement line into a comment line, or just delete it. Then assemble and link with the same procedure as before.
as103 program5.asm ld103 -m -T_CODE=40000000 program5.rf as103 -l -a m103.map program5.asm
The contents of the final list file program5.lst are as follows.
Note that the symbol table is not displayed.
program5.lst Page 1
*** PanaX series Series MN1030 Cross Assembler ***
Loc Object Line Source
1 #define DEBUG 2 3* M4 dat_set macro adr, dat 5 mov adr, A0 6 mov dat, D0 7 mov D0, (A0) 8 endm 9* 10 11 _CODE section CODE, PUBLIC, 1
40000000 12 main
13 #ifdef DEBUG 14X dat_set data1, 0x11 15 #else
M16 dat_set data1, 0x22 40000000 FCDC0C000040 16+ mov data1, A0 40000006 8022 16+ mov 0x22, D0 40000008 60 16+ mov D0, (A0)
17 #endif
18
19 _DATA section DATA, PUBLIC, 4 4000000C 00000000 20 data1 dd 0 40000010 00000000 21 data2 dd 0
22 end
Note how line number 14 is not assembled because the condition fails and how line number 16 is assembled instead.
Specify assembly conditions in the command
Until this point the condition has been specified by define in the source file, but it has been bothersome to edit the source file each time. The explanation below describes how to directly specify conditions with command options. This operation is valid only with regards to #ifdef.
40 Conditional Assembly and Linking
Page 53
Chapter 3 Introduction to Operation
In the previous file, you either deleted the define line or made it into a comment, so you can use it to once again select the true condition.
as103 -D DEBUG program5.asm ld103 -m -T_CODE=40000000 program5.rf as103 -l -a m103.map -D DEBUG program5.asm
D option Option to specify an identifier (DEBUG), having the same effect as specifying define
DEBUG in the source file.
The contents of the final list file program5.lst are as follows. Note that the symbol table is not displayed.
program5.lst Page 1
*** PanaX series Series MN1030 Cross Assembler ***
Loc Object Line Source
1 #define DEBUG 2 3* M4 dat_set macro adr, dat 5 mov adr, A0 6 mov dat, D0 7 mov D0, (A0) 8 endm 9* 10 11 _CODE section CODE, PUBLIC, 1
40000000 12 main
13 #ifdef DEBUG
M14 dat_set data1, 0x11 40000000 40000006 8011 14+ mov 0x11, D0 40000008 60 14+ mov D0, (A0)
4000000c 00000000 20 data1 dd 0 40000010 00000000 21 data2 dd 0
FCDC0CC000040
14+ mov data1, A0
15 #else
16X dat_set data1, 0x22
17 #endif
18
19 _DATA section DATA, PUBLIC, 4
22 end
Line number 14 was assembled. Check for yourself that omitting -D DEBUG will assemble line number 16 instead. This technique enables the programmer to freely choose assembly conditions with command option specifications.
There is also an assembler option for suppressing the source code lines not selected during conditional assembly. For further details, see Chapter 5 "Using the Assembler" and Chapter 6 "Using the Linker."
Conditional Assembly and Linking 41
Page 54
Chapter 3 Introduction to Operation
42 Conditional Assembly and Linking
Page 55

Chapter 4 Optimization

4
Page 56
Chapter 4 Optimization

4.1 Purpose of This Chapter

The assembler and linker examine source statements containing conditional branches, unconditional branches, subroutine calls, data transfer instructions, arithmetic instructions, logical instructions, bit manipulation instructions, and user-defined instructions to determine the shortest possible machine language instruction corresponding to the instruction.
This chapter uses examples to explain what optimization is.
NOTE: The assembler and linker make changes to object code, not instruction
mnemonics. Pay close attention to this point when viewing list files. When an @ is displayed before a line number in the list file, it indicates that the statement has been optimized.
44 Purpose of This Chapter
Page 57

4.2 Rules of Usage

To use the optimization function, optimization must be turned on by using the O opt ion or by placing an opt directive at the start of the source file.
opt on
NOTE: Optimization is off by default.
Chapter 4 Optimization
Rules of Usage 45
Page 58
Chapter 4 Optimization

4.3 Usage Example

Optimization Instructions
Optimization covers the following conditional branches, unconditional branches, subroutine calls, data transfer instructions, arithmetic instructions, logical instructions, bit manipulation instructions, and user-defined instructions.
Table 4-1 Optimized Conditional Branch Instructions
Instruction Type Branch Range
BLT label BGT label BGE label BLE label BCS label BHI label BCC label BLS label BEQ label BNE label BVC label BVS label BNC label BNS label
Relative branch instruction Branch within -128 to +127 bytes of the PC.
Table 4-2 Unconditional Branches and Subroutine Calls Subject to Optimization
Instruction Type Branch Range
BRA label Relative branch instruction Branch within -128 to +127 bytes of the PC CALL label CALLS label JMP label JSR label
Branch instruction Branch within the 4-gigabyte memory space.
46 Usage Example
Page 59
Table 4-3 Data Transfer Instructions Subject To Optimization
Instruction Type Branch Range
MOV (abs), An MOV (abs), Dn MOV An, (abs) MOV Dn, (abs) MOVBU (abs), Dn MOVBU Dn, (abs) MOVB (abs), Dn
Absolute addressing 16M-byte memory space
MOVB Dn, (abs) MOVHU (abs), Dn MOVHU Dn, (abs) MOVH (abs), Dn MOVH Dn, (abs) MOV (d, An), An MOV (d, An), Dn MOV (d, SP), An MOV (d, SP), Dn MOV An, (d, An) MOV An,(d, SP) MOV Dn, (d, An) MOV Dn, (d, SP) MOVBU (d, An), Dn MOVBU (d, SP), Dn MOVBU Dn,(d, An) MOVBU Dn, (d, SP) MOVB (d, An), Dn
Register relative indirect addressing
Branches possible to anywhere in the 4-gigabyte memory space
MOVB (d, SP), Dn MOVB Dn, (d, An) MOVB Dn, (d, SP) MOVHU (d, An), Dn MOVHU (d, SP), Dn MOVHU Dn, (d, An) MOVHU Dn, (d, SP) MOVH (d, An), Dn MOVH (d, SP), Dn MOVH Dn, (d, An) MOVH Dn, (d, SP) MOV imm, An MOV imm, Dn
Immediate addressing 32-bit immediate data.
Chapter 4 Optimization
Usage Example 47
Page 60
Chapter 4 Optimization
Instruction Type Branch Range
ADD imm, An ADD imm, Dn ADD imm, SP AND imm, Dn CMP imm, An CMP imm, Dn
Instruction Type Branch Range
OR imm, Dn XOR imm, Dn
Table 4-4 Arithmetic Instructions Subject To Optimization
Immediate addressing 32-bit immediate data
Table 4-5 Logical Instructions Subject To Optimization
Immediate addressing 32-bit immediate data.
Table 4-6 Logical Instructions Subject To Optimization
Instruction Type Branch Range
BTST imm, Dn Immediate addressing 32-bit immediate data.
48 Usage Example
Page 61
Table 4-7 Data Transfer Instructions Subject To Optimization
Instruction Type Branch Range
UDF00 imm, Dn UDF01 imm, Dn UDF02 imm, Dn UDF03 imm, Dn UDF04 imm, Dn UDF05 imm, Dn UDF06 imm, Dn UDF07 imm, Dn UDF08 imm, Dn UDF09 imm, Dn UDF10 imm, Dn UDF11 imm, Dn UDF12 imm, Dn UDF13 imm, Dn UDF14 imm, Dn UDF15 imm, Dn UDFU00 imm, Dn
Immediate addressing 32-bit immediate data
UDFU01 imm, Dn UDFU02 imm, Dn UDFU03 imm, Dn UDFU04 imm, Dn UDFU05 imm, Dn UDFU06 imm, dn UDFU07 imm, Dn UDFU08 imm, Dn UDFU09 imm, dn UDFU10 imm, Dn UDFU11 imm, Dn UDFU12 imm, Dn UDFU13 imm, Dn UDFU14 imm, Dn UDFU15 imm, Dn
Chapter 4 Optimization
Optimization processing
The assembler informs the linker about all instructions to be optimized. Based on the information from the assembler, the linker outputs instruction codes with the smallest code size.
Usage Example 49
Page 62
Chapter 4 Optimization
Optimization processing of conditional branch instructions
The linker resolves address values for labels when linking multiple files. In the example below, the linker will determine whether or not the label coded as an operand is within the allowable range of the current instruction. If not in range, the linker will replace it with instructions for a wider branch range.
Take the BEQ instruction for example.
BEQ LABEL
......
LABEL
The destination label of the BEQ instructions must be in the range -128 to +127. However, the assembler cannot make that determination, so the following determinations are made during assembly and linking.
Assembler processing
The assembler outputs information about instructions to be opti mized to the linker.
Linker processing
1. The linker inputs information from the assembler.
2. The linker determines if the branch destinations of conditional branches are in range.
3. If determined to be in range, the linker generates the normal code.
4. If determined to be not in range, the linker will substitute code that can branch correctly.
The substitution for the above example would be as follows.
BNE *+5 JMP LABEL
......
LABEL
50 Usage Example
Page 63
Optimization of function calls
This section describes the optimization of function calls by the linker. The assembler provides advanced processing for function calls. This processing uses a combination of
the call and ret instructions and the global and funcinfo directives. The following is an example.
global _0func
_TEXT section CODE, PUBLIC, 1
: call _0func (1) :
global _0func, _func _TEXT section CODE, PUBLIC, 1 _func
movm [D2], (SP) (2)
add -4, SP _0func funcinfo _func, 8, [D2]
:
:(3)
ret
Chapter 4 Optimization
(1) gives the call to the function _0func. (3) is the body of the function. (2) the section between the labels _func and _0func, saves a register and sets up the stack frame.
When this source file is assembled and linked, the linker eliminates section (2). This section is preserved when the symbol _func is referred.
For further details on machine instructions and directives, see the Instruction Manual and Section 9.4 "Writing Directives."
NOTE: This optimization of function calls is always carried out regardless of the state of
the optimization option (-O). It is suppressed throughout if even one of the source files to be linked contains a calls instruction with the operand (An).
Usage Example 51
Page 64
Chapter 4 Optimization
Table 4-8 Substituted Instructions For Out-Of Range Conditional Branch Instructions
Source Instruction Candid ate instruction 1 Candidate instruction 2 Candidate instruction 3
BLT LABEL BRA LABEL BGE *+5
BGT LABEL BGT LABEL BLE *+5
BGE LABEL BGE LABEL BLT *+5
BLE LABEL BLE LABEL BGT * +5
BCS LABEL BCS LABEL BCC *+5
BHI LABEL BHI LABEL B LS *+5
BCC LABEL BCC LABEL BCS *+5
BLS LABEL BLS LABEL BHI *+5
BEQ LABEL BEQ LABEL BNE *+5
BNE LABEL BNE LABEL BEQ *+5
BVC LABEL BVC LABEL BVS *+6
BVS LABEL BVS LABEL BVC *+6
BNC LABEL BNC LABEL BNS *+6
BNS LABEL BNS LABEL BNC *+6
JMP LABEL
JMP LABEL
JMP LABEL
JMP LABEL
JMP LABEL
JMP LABEL
JMP LABEL
JMP LABEL
JMP LABEL
JMP LABEL
JMP LABEL
JMP LABEL
JMP LABEL
JMP LABEL
BGE *+7 JMP LABEL
BLE *+7 JMP LABEL
BLT *+7 JMP LABEL
BGT *+7 JMP LABEL
BCC *+7 JMP LABEL
BLS *+7 JMP LABEL
BCS *+7 JMP LABEL
BHI *+7 JMP LABEL
BNE *+7 JMP LABEL
BEQ *+7 JMP LABEL
BVS *+8 JMP LABEL
BVC *+8 JMP LABEL
BNS *+8 JMP LABEL
BNC *+8 JMP LABEL
Optimization of branches
For unconditional branch instructions, a JMP label instruction is replaced by a BRA label instruction if the jump target is within the range available for the shorter, relative branch instruction BRA. Similarly, a CALL label, CALLS label, or JSR label instruction is replaced by the shorter version with a 16-bit displacement (d16,PC) instead of the one with the 32-bit displacement (d32,PC).
The following table shows the possibilities for optimizing the unconditional branch instructions and the subroutine call instructions.
Table 4-9 Optimization of branches
Source Instruction First Candidate Second Candidate Third Candidate
BRA label BRA label JMP label JMP label JMP label BRA label JMP label JMP label CALL label CALL label CALL label CALLS label CALLS label CALLS label JSR label JSR label JSR label
52 Usage Example
Page 65
Chapter 4 Optimization
Optimization of data transfer, arithmetic, logical, bit manipulation and user-defined instructions
For data transfer, arithmetic, logical, bit manipulation, and user-defined instructions, the assembler uses the shortest instruction available for expressing the specified immediate data, memory address, or dis­placement data. The user thus obtains optimal code size without having to worry about instruction vari­ants.
The following table shows the possibilities for optimizing data transfer, arithmetic, logical, bit manipu­lation, and user-defined instructions.
Table 4-10 optimization of data transfer, arithmetic, logical bit manipulation...
Source instruction First Candidate Second Candidate Third Candidate
MOV(abs), An MOV(abs16), An MOV (abs32), An MOV (abs), Dn MOV(abs16), Dn MOV (abs32), Dn MOV(d,An), An MOV(d8, An), An MOV(d16,An), An MOV (d32, An), An MOV (d, An), Dn MOV (d8, An), Dn MOV (d16, An), Dn MOV (d32, An), Dn MOV (d, SP), An MOV(d8, SP), An MOV(d16, SP), An MOV (d32, SP), An MOV (d, SP), Dn MOV (d8, SP), Dn MOV (d16, SP), Dn MOV (d32, SP), Dn MOV An, (abs) MOV An,(abs16) MOV An, (abs32) MOV An, (d, An) MOV An, (d8, An) MOV An, (d16, An) MOV An, (d32, An) MOV An, (d, SP) MOV An, (d8, SP) MOV An, (d16, SP) MOV An, (d32, SP) MOV Dn (abs) MOV Dn (abs 16) MOV Dn, (abs32) MOV Dn, (d, An) MOV Dn, (d8, An) MOV Dn, (d16, An) MOV Dn, (d32, An) MOV Dn, (d, SP) MOV Dn, (d8, SP) MOV Dn, (d16, SP) MOV Dn, (d32, SP) MOV imm, An MOV imm8, An MOV imm16, An MOV imm32, An MOV imm, Dn MOV imm8, Dn MOV imm16, Dn MOV imm32, Dn MOVBU (abs),Dn MOVBU (abs16),Dn MOVBU (abs32),Dn MOVBU (d,An),Dn MOVBU (d8,An),Dn MOVBU (d16,An),Dn MOVBU (d32,An),Dn MOVBU (d,SP),Dn MOVBU (d8,SP),Dn MOVBU (d16,SP),Dn MOVBU (d32,SP),Dn MOVBU Dn,(abs) MOVBU Dn,(abs16) MOVBU Dn,(abs32) MOVBU Dn,(d,An) MOVBU Dn,(d8,An) MOVBU Dn,(d16,An) MOVBU Dn,(d32,An) MOVBU Dn,(d,SP) MO V BU Dn,(d8,SP) MOVBU Dn,(d16,SP) MOVBU Dn,(d32,SP) MOVB (abs),Dn MOVB (abs16),Dn MOVB (abs32),Dn MOVB (d,An),Dn MOVB (d8,An),Dn MOVB (d16,An),Dn MOVB (d32,An),Dn MOVB (d,SP),Dn MOVB (d8,SP),Dn MOVB (d16,SP),Dn MOVB (d32,SP),Dn MOVB Dn,(abs) MOVB Dn,(abs16) MOVB Dn,(abs32) MOVB Dn,(d,An) MOVB Dn,(d8,An) MOVB Dn,(d16,An) MOVB Dn,(d32,An) MOVB Dn,(d,SP) MOVB Dn,(d8,SP) MOVB Dn,(d16,SP) M OVB Dn,(d32,SP) MOVHU (abs),Dn MOVHU (abs16),Dn MOVHU (abs32),Dn MOVHU (d,An),Dn MOVHU (d8,An),Dn MOVHU (d16,An),Dn MOVHU (d32,An),Dn MOVHU (d,SP),Dn MOVHU (d8,SP),Dn MOVHU (d16,SP),Dn MOVHU (d32,SP),Dn MOVHU Dn,(abs) MOVHU Dn,(abs16) MOVHU Dn,(abs32) MOVHU Dn,(d,An) MOVHU Dn,(d8,An) MOVHU Dn,(d16,An) MOVHU Dn,(d32,An) MOVHU Dn,(d,SP) MOVHU Dn,(d8,SP) MOVHU Dn,(d16,SP) MOVHU Dn,(d32,SP) MOVH (abs),Dn MOVH (abs16),Dn MOVH (abs32),Dn MOVH (d,An),Dn MOVH (d8,An),Dn MOVH (d16,An),Dn MOVH (d32,An),Dn
Usage Example 53
Page 66
Chapter 4 Optimization
Table 4-10 optimization of data transfer, arithmetic, logical bit manipulation...
Source instruction First Candidate Second Candidate Third Candidate
MOVH (d,SP),Dn MOVH (d8,SP),Dn MOVH (d16,SP),Dn MOVH (d32,SP),Dn MOVH Dn,(abs) MOVH Dn,(abs16) MOVH Dn,(abs32) MOVH Dn,(d,An) MOVH Dn,(d8,An) MOVH Dn,(d16,An) MOVH Dn,(d32,An) MOVH Dn,(d,SP) MOVH Dn,(d8,SP) MOVH Dn,(d16,SP) MOVH Dn,(d32,SP) ADD imm,An ADD imm8,An ADD imm16,An ADD imm 32,An ADD imm,Dn ADD imm8,Dn ADD imm16,Dn ADD imm 32,Dn ADD imm,SP AD D imm8,SP ADD imm16,SP ADD imm32,SP AND imm,Dn AND imm8,Dn AND imm16,Dn AND imm 32,Dn CMP imm,An CMP imm8,An CMP imm16,An CMP imm32,An CMP imm,Dn CMP imm8,Dn CMP imm16,Dn CMP imm32,Dn OR imm,Dn OR imm8,Dn OR imm16,Dn OR imm32,Dn XOR imm,Dn XOR imm16,Dn XOR imm32,Dn BTST imm,Dn BTST imm8,Dn BTST imm16,Dn BTST imm32,Dn UDF00 imm,Dn UDF00 imm8,Dn UDF00 imm16,Dn UDF00 imm32,Dn UDF01 imm,Dn UDF01 imm8,Dn UDF01 imm16,Dn UDF01 imm32,Dn UDF02 imm,Dn UDF02 imm8,Dn UDF02 imm16,Dn UDF02 imm32,Dn UDF03 imm,Dn UDF03 imm8,Dn UDF03 imm16,Dn UDF03 imm32,Dn UDF04 imm,Dn UDF04 imm8,Dn UDF04 imm16,Dn UDF04 imm32,Dn UDF05 imm,Dn UDF05 imm8,Dn UDF05 imm16,Dn UDF05 imm32,Dn UDF06 imm,Dn UDF06 imm8,Dn UDF06 imm16,Dn UDF06 imm32,Dn UDF07 imm,Dn UDF07 imm8,Dn UDF07 imm16,Dn UDF07 imm32,Dn UDF08 imm,Dn UDF08 imm8,Dn UDF08 imm16,Dn UDF08 imm32,Dn UDF09 imm,Dn UDF09 imm8,Dn UDF09 imm16,Dn UDF09 imm32,Dn UDF10 imm,Dn UDF10 imm8,Dn UDF10 imm16,Dn UDF10 imm32,Dn UDF11 imm,Dn UDF11 imm8,Dn UDF11 imm16,Dn UDF11 imm32,Dn UDF12 imm,Dn UDF12 imm8,Dn UDF12 imm16,Dn UDF12 imm32,Dn UDF13 imm,Dn UDF13 imm8,Dn UDF13 imm16,Dn UDF13 imm32,Dn UDF14 imm,Dn UDF14 imm8,Dn UDF14 imm16,Dn UDF14 imm32,Dn UDF15 imm,Dn UDF15 imm8,Dn UDF15 imm16,Dn UDF15 imm32,Dn UDFU00 imm,Dn UDFU00 imm8,Dn UDFU00 imm16,Dn UDFU00 imm32,Dn UDFU01 imm,Dn UDFU01 imm8,Dn UDFU01 imm16,Dn UDFU01 imm32,Dn UDFU02 imm,Dn UDFU02 imm8,Dn UDFU02 imm16,Dn UDFU02 imm32,Dn UDFU03 imm,Dn UDFU03 imm8,Dn UDFU03 imm16,Dn UDFU03 imm32,Dn UDFU04 imm,Dn UDFU04 imm8,Dn UDFU04 imm16,Dn UDFU04 imm32,Dn UDFU05 imm,Dn UDFU05 imm8,Dn UDFU05 imm16,Dn UDFU05 imm32,Dn UDFU06 imm,Dn UDFU06 imm8,Dn UDFU06 imm16,Dn UDFU06 imm32,Dn UDFU07 imm,Dn UDFU07 imm8,Dn UDFU07 imm16,Dn UDFU07 imm32,Dn UDFU08 imm,Dn UDFU08 imm8,Dn UDFU08 imm16,Dn UDFU08 imm32,Dn UDFU09 imm,Dn UDFU09 imm8,Dn UDFU09 imm16,Dn UDFU09 imm32,Dn UDFU10 imm,Dn UDFU10 imm8,Dn UDFU10 imm16,Dn UDFU10 imm32,Dn UDFU11 imm,Dn UDFU11 imm8,Dn UDFU11 imm16,Dn UDFU11 imm32,Dn UDFU12 imm,Dn UDFU12 imm8,Dn UDFU12 imm16,Dn UDFU12 imm32,Dn UDFU13 imm,Dn UDFU13 imm8,Dn UDFU13 imm16,Dn UDFU13 imm32,Dn UDFU14 imm,Dn UDFU14 imm8,Dn UDFU14 imm16,Dn UDFU14 imm32,Dn UDFU15 imm,Dn UDFU15 imm8,Dn UDFU15 imm16,Dn UDFU15 imm32,Dn
54 Usage Example
Page 67
Chapter 4 Optimization
Example: branch destination of conditional branch instruction within range
This example shows a branch in the permitted range (-128 to 127 of PC) of a BCC LABEL conditional branch instruction.
The source list is as follows.
opt on _TEXT section CODE, PUBLIC,1 sub_func
mov 0, D2
cmp D1, D2 addr_set bcc func_end
org addr_set+127 func_end
rts
end
The final list file after assembly is shown next. The start address during linking is assumed to be 40000000 (hex.). The @ mark on line number 6 indicates that the instruction was the object o f optim i­zation. Since the target address is within the range of a relative jump, the assembler generates a BCC LABEL instruction.
opt1.lst Page 1
*** PanaX series Series MN1030 Cross Assembler ***
Loc Object Line Source
1 opt on
2 _TEXT section CODE, PUBLIC, 1 40000000 3 sub_func 40000000 8A00 4 mov 0, D2 40000002 A6 5 cmp D1, D2 40000003 C67F @6 addr_set bcc func_end
7
8 org addr_set+127 40000082 9 func_end 40000082 F0FC 10 rts
11 end
opt1.lst Page 2
*** Symbol Table ***
40000000 T sub_func 40000003 T addr_set 40000082 T func_end
Usage Example 55
Page 68
Chapter 4 Optimization
Example: branch destination of conditional branch instruction out of range
This example shows a branch outside the permitted range (-128 to +127 of PC) of a BCC LABEL con­ditional branch instruction.
The source list is as follows.
opt on _TEXT section CODE, PUBLIC,1 sub_func
mov 0, D2
cmp D1, D2 addr_set bcc func_end
org addr_set+128 func_end
rts
end
The final list file after assembly is shown next. LABEL exceeds the permitted branch range of BCC LA­BEL, so the code has been converted to BCS *+5, JMP LABEL. Note that the mnemonics and object code are different.
opt2.lst Page 1
*** PanaX series Series MN1030 Cross Assembler ***
Loc Object Line Source
1opton
2 _TEXT section CODE, PUBLIC, 1 40000000 3 sub_func 40000000 8A00 4 mov 0, D2 40000002 A6 5 cmp D1, D2 40000003 C405CC0080 @6 addr_set bcc func_end
7
8 org addr_set+128 40000083 9 func_end 40000083 F0FC 10 rts
11 end
12
opt2.lst Page 2
*** Symbol Table ***
56 Usage Example
40000000 T sub_func 40000003 T addr_set 40000083 T func_end
Page 69
Example: unconditional branch instruction converted to relative branch
This example shows the branch destination of a JMP LABEL unconditional branch instruction within the permitted range (-128 to +127 of PC) for relative branching.
The source list is as follows.
opt on _TEXT section CODE, PUBLIC,1 sub_func addr_set jmp func_end
org addr_set+127 fun_end
end
The final list file after assembly is shown next. The branch destination of the JMP LABEL instruction on line number 4 is in the permitted range for relative b ranch ing, so it has been converted to BRA LA­BEL. Note that the mnemonics and object code are different.
Chapter 4 Optimization
opt3.lst Page 1
*** PanaX series Series MN1030 Cross Assembler ***
Loc Object Line Source
1 opt on
2 _TEXT section CODE, PUBLIC, 1 40000000 3 sub_func 40000000 CA7F @4 addr_set jmp func_end
5
6 org addr_set+127 4000007f 7 func_end 4000007f F0FC 8 rts
9 end
opt3.lst Page 2
*** Symbol Table ***
40000000 T sub_func 40000000 T addr_set 4000007f T func_end
Usage Example 57
Page 70
Chapter 4 Optimization
Example: subroutine call converted to a relative branch
This section gives an example of a CALLS LABEL instruction with a target address within the range of a relative jump--that is, between -32,768 and +32,767 from the current program counter.
The source list is as follows.
opt on _TEXT section CODE, PUBLIC,1 sub_func addr_set calls func_end
org addr_set+128 func_end rts
end
The final list file after assembly is shown next. Since the CALLS LABEL instruction in line four con­tains a target address that may be expressed with a 2-byte relative branch, the assembler replaces it with the CALLS LABEL variant with a 2-byte address field. Note that the mnemonics and object code are different.
opt4.lst Page 1
*** PanaX series Series MN1030 Cross Assembler ***
Loc Object Line Source
1 opt on
2 _TEXT section CODE, PUBLIC, 1 40000000 3 sub_func 40000000 FAFF8000 @4 addr_set Calls func_end
5
6 org addr_set+128 40000080 7 func_end 40000080 F0FC 8 rts
9end
opt4.lst Page 2
*** Symbol Table ***
40000000 T sub_func 40000000 T addr_set 40000080 T func_end
58 Usage Example
Page 71

Chapter 5 Using Assembler

5
Page 72
Chapter 5 Using Asssembler

5.1 Purpose of This Chapter

This Chapter describes assembler operating procedures. Chapter 3 "Introduction to Operation" described the basic operation of the assembler and linker, but this one describes the many options available with the assembler and gives examples.
60 Purpose of This Chapter
Page 73

5.2 Starting Assembler

The assembler is started by entering the command name and the desired parameters. The command name differs depending on the device being used. This chapter uses the terminology of as103 as its general format.
General format of commands
Below is the general format of the command to use when starting the assembler.
as103 [options] source_filename
Contents of brackets [ ] may be omitted.
Specifying options
Chapter 5 Using Assembler
An option starts with a hyphen (-) as the options specifier, followed by a character that indicate the particular option.
-l
Option specifications are case sensitive, so upper case and lower case letters must be specified correctly.
-Lc
Single-character options not accompanied by parameters can be specified as multiple characters following the hyphen (-) option specifier. The order is optional.
-gl
When an option is accompanied by a parameter and other options are to follow, add a space after the parameter, and follow with the hyphen (-) option specifier.
-I/user/source -Li -Lc
Parameters can be specified right after the option character or separated by one space.
-I/user/source or -I /user/source
When options are omitted, assembly will be perform in accordance with the default interpretations built in to the assembler. Refer to section 5.3, "Command Options", for default interpretations.
NOTE: Omitting the path specifies that the source file is in the current directory.
Specifying a path for the source file does not affect the listing file and relocatable object file. They are always created in the current directory. Note, however, that the -o option is available for creating the relocat ab le ob je ct file in an ot he r directory.
Starting Assembler 61
Page 74
Chapter 5 Using Asssembler
Summary of options
The following Table lists the available command line options.
Table 5-1 Assembler Options
Option Type Symbol Description
o file_name Specify the relocatable object file name to be output. l Output a list file. Li Do not output files included by include to the list file. Lm Do not output assembler source created by macro expansion using
Output file
Ls Do not output a symbol table to the list file. Lc Do not output source statements that were not assembled due to
a map_file name Read the map file to output a list file with resolved addresses.
macro or irp to the list file. Output only the machine language code.
unfulfilled conditions of conditional assembly to the list file
Error message options
Preprocessor options
Program generation options
j Output error and warning messages in Japanese. Output will be to the
screen and when a list file is specified, to the list file
Je Output error and warning messages in Japanese using EUC encoding to
the console and, if specified, the listing file.
Js Output error and warning messages in Japanese using Shift JIS
encoding to the console and, if specified, the listing file.
Jj Output error and warning messages in Japanese using JIS encoding to
the console and, if specified, the listing file.
e Output error and warning messages in English. Output will be to the
screen and, when a list file is specified, to the list file.
W number Do not output warning messages of the specified number. Output will
not be performed to either the screen or list file. Refer to chapter 13, "Error Messages", for warning messages and their corresponding
numbers Wall Do not output any warning messages. I path_name S pecify the path name of the directory that contains files specified by
include. D identifier Specify an identifier to be used by ifdef during conditional assembly. g Output debug information to the relocatable object file. Od Turn off optimization. O Turn on optimization.
Others
62 Starting Assembler
h Display a listing of available assembler options on the console. v Display the assembler's version number on the console.
Page 75

5.3 Command Options

This section describes the options available for the assembler. The assembler has an abundance of options for controlling assembler processing and output files.
Not all options are available at the same time. Certain options have default values that are used when the option is not specified. These defaults have been chosen to reflect the most frequently used settings. As long as the default settings are acceptable, it is possible to omit most options. For the details of the interpretation when an option is omitted, see the description below for that option.
Chapter 5 Using Assembler
Command Options 63
Page 76
Chapter 5 Using Asssembler

5.3.1 Output File Options

o file_name Specify the relocatable object file name to be output
Functional description
This option specifies the relocatable object file name to be output by the assembler. If the specified file already exists, its previous contents will be erased. If a path name that does not exist is specified, the assembler will display an error message and suspend processing.
NOTE: Because the @ symbol is used as the characte r for sp ecifying para meter files, it
cannot be used as the first character of file names.
Rules of Use
This option is specified with the hyphen (-) option specification character, followed by the lower-case letter 'o', then either immediately followed by the file name or a space and the file name. If the file is to be output to the current directory, only the file name needs to b e specif ied. If t he file is to be o utput to a different directory, both a path name and a file name must be specified.
as103 -o /user/obj/test.rf main.asm
Default Specification
The assembler creates a file with the same name as the input file, but with the extension changed to .rf in the current directory.
Operation Example
The following command line assembles the source file samp1.asm in the current directory and creates the relocatable object file /user/obj/samp1.rf. It does not create a listing file.
as103 -o/user/obj/sampl.rf sampl.asm
64 Command Options
Page 77
l Output a list file
Functional Description
This option outputs a list file. The file name of the list file will be the source file name with the extension .lst. The list file will be generated in the same directory as the source file.
If any assembler errors are detected, error information will also be written to the list file.
Rules of Use
This option is specified with the hyphen (-) option specification character, followed by the lower-case letter 'l'.
as103 -l sample.asm
Default Specification
Chapter 5 Using Assembler
No list file will be output.
Command Options 65
Page 78
Chapter 5 Using Asssembler
Li Do not output files included by include to the list file
Functional Description
This option suppresses output of source file contents included by assembler directive (include) to the list file. However, the machine language code will be written to the relocatable object file.
This option is convenient when you need a listing only for a particular source file while debugging . The Li option specification will be ignored for source files that do not have any include statements.
Rules of Use
This option is specified with the hyphen (-) option specification character, followed by the upper-case letter 'L' and lower-case letter 'i'. The pair of characters of Li are handled as a single option.
as103 -Li -l sample.asm
NOTE: This option is used in conjunction with the l option (lower-case 'l', list output).
Default Specification
Source files included by include will be output to the list file.
Operation Example
The following command line assembles the source file samp1.asm and creates a listing file samp1.lst that suppresses all text merged with the assembler directive include.
as103 -l -Li sampl.asm
NOTE: Files included with include must not terminate with the end directive.
66 Command Options
Page 79
Lm Do not output files included by include to the list file
Functional Description
This option suppresses output of assembler source created by macro expansion using macro directives macro and irp to the list file. Only display of machine language instruction mnem onics will be suppressed; machine language code will be output.
By using names that represent their processing actions, macro names can make listings easier to read. In such cases, listings without expanded mnemonics will be easier to look at. This is why the Lm option is provided.
If the l option is not specified, the Lm option will be ignored even if specified. Source files with no macro expansion will be assembled normally even if assembled with the Lm option.
Rules of Use
Chapter 5 Using Assembler
This option is specified with the hyphen (-) option specification character, followed by the upper-case letter 'L' and lower-case letter 'm'. The pair of characters of Lm are handled as a single option.
as103 -Lm -l sample.asm
NOTE: The Lm option is specified with the hyphen (-) option specification character
Default Specification
Source statements expanded from macros will be output to the list file.
Operation Example
The following command line assembles the source file samp1.asm and creates a listing file samp1.lst that suppresses all text generated by the expansion of macros.
as103 -l -Lm sampl.asm
Command Options 67
Page 80
Chapter 5 Using Asssembler
Lc
Do not output source statements that were not assembled due to unfulfilled conditions of conditional assembly to the list file
Functional Description
This option suppresses output of blocks of unsatisfied conditions with conditional assembly to the list file. It also suppresses source statements of conditional directives.
Rules of Use
This option is specified with the hyphen (-) option specification character, followed by the upper-case letter 'L' and lower-case letter 'c'. The pair of characters of Lc are handled as a single option.
as103 -Lc -l sample.asm
NOTE: This option is used in conjunction with the l option (lower-case 'l', list output).
Default Specification
Blocks of unsatisfied conditions will be output to the list file.
Operation Example
The following command line assembles the source file samp1.asm and creates a listing file samp1.lst that suppresses all text from conditional assembly blocks for which the condition is not satisfied.
as103 -l -Lc sampl.asm
68 Command Options
Page 81
Ls Do not output a symbol table to the list file
Functional Description
This directive suppresses output of a symbol table when the list file is output.
Rules of Use
This option is specified with the hyphen (-) option specification character, followed by the upper-case letter 'L' and lower-case letter 's'. The pair of characters of Ls are handled as a single option.
as103 -Ls -l sample.asm
NOTE: This option is used in conjunction with the l option (lower-case 'l', list output
Chapter 5 Using Assembler
Default Specification
A symbol table will be output.
a map_filename Read the map file to output a list file with resolved address
Functional Description
This option is used to generate a final list file with resolved addresses. First you must have generated a map file (.map) by specifying the m option with the linker. Then using
this map file, reassemble with the a option to generate the final list file. Specifying the wrong map file or specifying the different option from the one assembled at first results
in an error.
Rules of Use
This option is specified with the hyphen (-) option specification character, followed by the lower-case letter 'a', then followed by the map file name.
as103 -a sample.map -l sample.asm
NOTE: When specifying the a option, always specify the l option to output a list file. No
list file will be generated if only the a option is specified. Specify a option and 1 option adding to the first assembled option for the final list file.
Default Specification
The assembler will not generate a final list file with addresses resolved by a map file.
Command Options 69
Page 82
Chapter 5 Using Asssembler

5.3.2 Error Message Options

j Output error and warning messages in Japanese
Functional Description
This option causes all error and warning messages and help screens sent to the console or the listing file to appear in Japanese.
The character coding depends on the host machine and the operating system.
Host machine Character coding
Sun/Sparc EUC DOS/V Shi ft JIS PC/AT not supported
Rules of Use
To specify the option, enter the hyphen (-) followed by the lower case letter 'j'.
as103 -j sample.asm
NOTE: This option is not available on PC/AT machines.
Default Specification
The default language used depends on the host machine and the operating system
Host machine Message Language
Sun/Sparc English DOS/V Japanese in Shift JIS PC/AT English
It is also possible to change the default message specification with an entry in the assembler's start-up file. See Chapter 1 "Getting Started" Section 1.5 "Setup."
70 Command Options
Page 83
Chapter 5 Using Assembler
Je Output error and warning messages in Japanese using EUC encoding
Functional Description
This option causes all error and warning messages and help screens sent to the console or the listing file to appear in Japanese using EUC coding.
Rules of Use
To specify the option, enter the hyphen (-) followed by the upper case letter 'J' and the lower case letter 'e'. The two letters together function as a single option.
as103 -Je sample.asm
NOTE: This option is not available on DOS/V or PC/AT machines.
Default Specification
The default language used depends on the host machine and the operating system.
Host machine Message language
Sun/Sparc English DOS/V Japanese in Shift JIS PC/AT English
It is also possible to change the default message specification with an entry in the assembler's start-up file. See Chapter 1 "Getting Started" Section 1.5 "Setup."
Command Options 71
Page 84
Chapter 5 Using Asssembler
Js Output error and warning messages in Japanese using Shift JIS encoding
Functional Description
This option causes all error and warning messages and help screens sent to the console or the listing file to appear in Japanese using Shift JIS coding.
Rules of Use
To specify the option, enter the hyphen (-) followed by the upper case letter 'J' and the lower case letter 's'. The two letters together function as a single option.
as103 -Js sample.asm
NOTE: This option is not available on PC/AT machines.
Default Specification
The default language used depends on the host machine and the operating system.
Host machine Message language
Sun/Sparc English DOS/V Japanese in Shift JIS PC/AT English
It is also possible to change the default message specification with an entry in the assembler's start-up file. See Chapter 1 "Getting Started" Section 1.5 "Setup."
72 Command Options
Page 85
Chapter 5 Using Assembler
Jj Output error and warning messages in Japanese using JIS encoding
Functional Description
This option causes all error and warning messages and help screens sent to the console or the listing file to appear in Japanese using JIS coding.
Rules of Use
To specify the option, enter the hyphen (-) followed by the upper case letter 'J' and the lower case letter 'j'. The two letters together function as a single option.
as103 -Jj sample.asm
NOTE: This option is not available on DOS/V or PC/AT machines.
Default Specification
The default language used depends on the host machine and the operating system.
Host machine Message language
Sun/Sparc English DOS/V Japanese in Shift JIS PC/AT English
It is also possible to change the default message specification with an entry in the assembler's start-up file. See Chapter 1 "Getting Started" Section 1.5 "Setup."
Command Options 73
Page 86
Chapter 5 Using Asssembler
e Output error and warning messages in English
Functional Description
This option causes all error and warning messages and help screens sent to the console or the listing file to appear in English.
Rules of Use
To specify the option, enter the hyphen (-) followed by the lower case letter 'e'.
as103 -e sample.asm
Default Specification
The default language used depends on the host machine and the operating system.
Host machine Message language
Sun/Sparc English DOS/V Japanese in Shift JIS PC/AT English
It is also possible to change the default message specification with an entry in the assembler's start-up file. See Chapter 1 "Getting Started" Section 1.5 "Setup."
74 Command Options
Page 87
W number Do not output warning messages of the specified number
Functional Description
This option suppresses output of warning messages generated during assembler operation. For a list of warning messages and their numbers, see Chapter 13 "Error Messages."
The assembler ignores specifications for warning numbers that do not have messages assigned to them.
Rules of Use
To specify the option, enter the hyphen (-) followed by the upper case letter 'W' and the number.
as103 -W 2001 sample.asm
Default Specification
The default is to display all warning messages.
Chapter 5 Using Assembler
Wall Do not output any warning messages
Functional Description
This option suppresses output of all warning messages generated during assembler operation.
Rules of Use
To specify the option, enter the hyphen (-) followed by the letters 'Wall'.
as103 -Wall sample.asm
Default Specification
The default is to display all warning messages.
Command Options 75
Page 88
Chapter 5 Using Asssembler

5.3.3 Preprocessor Options

I path_name Specify the trace directory of the include file.
Functional Description
Trace from the directory that specifies the include file in the assembler source file. If the absolute path starting with “/” is written, tis option is invalid. Assembler traces the include file from the directory as follows.
1. Directory contains assembler source file
2. Directory specified with -I option.
Rules of Use
This option is specified with the hyphen(-) option specification character, followed by the upper-case letter ‘I’, then either immediately followed by the path name or a space and the path name.
as103 -I/user/defs main.asm
Default Specification
If not specifying this option, the assembler traces the directory (1) written above.
76 Command Options
Page 89
Chapter 5 Using Assembler
D identifier Specify an identifier to be used by ifdef during conditional assembly
Functional Description
The assembler directives #ifdef, #else, and #endif select which source statements are to be assembled depending on whether an identifier has been defined by a define directive. The D option has the same function as the define directive, but with direct specification from the command line.
Identifier specifications by define directives in source statements may be omitted. The statements to be assembled can instead be selected by specifying identifiers with the D option as needed.
Thus, the D option allows conditions to be set freely at the assembly stage without fixing the conditions with define directives in source statements.
There are two conditional assembly directives that can make use of the D option. ifdef, ifndef No error will occur if identifiers specified by the D option are not used in the source file. Assembly will
process as though conditions are unfulfilled.
Rules of Use
This option is specified with the hyphen (-) option specification character, followed by the upper-case letter 'D', then followed by the identifier. A space can be inserted between D and the identifier. The identifier must exactly match the string specified by #ifdef. Characters are case-sensitive.
as103 -D VERSION sample.asm
Default Specification
Unfulfilled conditions will be selected. The #else to #endif blocks will be assembled.
Command Options 77
Page 90
Chapter 5 Using Asssembler

5.3.4 Program Generation Options

g Output debug information to the relo catable object file
Functional Description
This option causes the assembler to include in the relocatable object file information for use in debugging at the source code level.
This information includes the following:
Names and addresses of variables
Detailed information on variables
Correspondences between line numbers and code addresses
With this information, debugging is much easier since the user can specify variables by name instead of by address.
NOTE: This option must also be specified when linking. If the g option is not specified for
either the assembler or linker, debug information will not be output to the executable format file (.EX).
NOTE: If the number of lines per source file exceeds 65535, some part of the debug
information will not be output. Make sure when you debug programs, one source file can contain up to 65535 lines. Divide a file with more than 65535 lines to avoid errors. Note that the file names or line numbers in error messages will not be shown if the linker generates error or warning messages after the line 65535.
Rules of Use
This option is specified with the hyphen (-) option specification character, followed by the lower-case letter 'g'.
as103 -g sample.asm
Default Specification
Debug information will not be output.
78 Command Options
Page 91
O Turn on optimization
Functional Description
This option enables optimization of instructions by the assembler and linker. For the instructions subject to optimization, see Chapter 4 "Optimization Functions."
Rules of Use
To specify the option, enter the hyphen (-) followed by the upper case letter 'O'.
as103 -O sample.asm
Default Specification
The default is to suppress optimization. It is also possible to change the optimization default with an entry in the assembler's start-up file. See
Chapter 1 "Getting Started" Section 1.5 "Setup."
Chapter 5 Using Assembler
Od Turn off optimization
Functional Description
This option disables optimization of instructions by the assembler and linker. For the instructions subject to optimization, see Chapter 4 "Optimization Functions."
This option overrides any opt on directives included in the source files. For further details on the opt on directive, see Chapter 9 "Writing Machine Language Instructions and Directives" Section 9.4 "Writing Directives" Section 9.4 "opt."
Rules of Use
To specify the option, enter the hyphen (-) followed by the upper case letter 'O' and the lower case letter 'd'. The two letters together function as a single option.
as103 -Od sample.asm
Default Specification
The default is to suppress optimization. It is also possible to change the optimization default with an entry in the assembler's start-up file. See
Chapter 1 "Getting Started" Section 1.5 "Setup."
Command Options 79
Page 92
Chapter 5 Using Asssembler

5.3.5 Other Options

h Display listing of available assembler option on the console
Functional Description
This option displays assembler command options and their descriptions to the screen. The -j, -Je, -Js, -Jj, and -e options, if they appear, control the language and the coding scheme used to
display this information.
Rules of Use
To specify the option, enter the hyphen (-) followed by the lower case letter 'h'.
as103 -h
NOTE: Even if the h option is not specified, input of AS103 alone will also display the
help screen. When displaying help information, version number is also displaye d on the screen.
Default Specification
Help information will not be displayed to the screen.
v Display the assembler's version number on the console
Functional Description
This option displays the assembler's version number on the console.
Rules of Use
To specify the option, enter the hyphen (-) followed by the lower case letter 'v'.
as103 -v
Default Specification
The default is to not display the version number.
NOTE: Even if the v option is not specified, input of as103 alone will also display the
80 Command Options
help screen. When displaying help information, version number is also displaye d on the screen.
Page 93

5.4 Operation Examples

There are three steps to perform when you need a final list file with resolved addresses.
1. With the assembler, generate a relocatable object file (.rf).
2. With the linker, generate an executable format file (.ex) and map file (.map).
3. With the assembler again, use the map file to generate a final list file (.lst) with addresses resolved by the linker.
Program assembly
Generation of a list file with the l option on the first assembly will not resolve addresses, so you would not do so unless you have some special purpose. For the same reason, the Li, Lm, and Lc options are also not used.
Chapter 5 Using Assembler
as103 -g sample.asm
The above command assembles the source file (sample.asm) in the current directory, and generates a relocatable object file (sample.rf) with debug information in the current directory.
as103 -g -D VERSION -o test.rf /user/source/main.asm
The above command assembles the source file (main.asm) in the /user/source directory. For conditional assembly of the source file, assembly will proceed as though VERSION were defined.
The above command also generates a relocatable object file named test.rf with debug information in the current directory.
as103 -g -o test.rf -I /user/lib sample.asm
The above example assembles the source file (sample.asm) in the current directory. Files specified by include will be read from the /user/lib directory.
The above command also generates a relocatable object file named test.rf with debug information in the current directory.
as103 -I/user/defs -o /user/src/sample.rf -D TYPE file.asm
The above example assembles the source file (file.asm) in the current directory. For conditional assembly (ifdef), assembly will proceed as though TYPE were declared. The assembler reads files specified with the include directive from the directory /user/defs.
The above example will store the relocatable object file with name sample.rf in the /user/src directory.
Operation Examples 81
Page 94
Chapter 5 Using Asssembler
Generation of final list file with resolved program addresses
The final list file is generated as follows.
1. First use the assembler to generate a relocatable object file. Valid options at this stage are o, I, D, g, and the optimization options (O, Od).
2. Next use the linker to generate an executable format file by specifying the start address of each section and linking multiple files. Specify the linker's m option to generate the map file. Refer to chapter 6, "Using The Linker", for details.
3. Use the assembler once more to assemble the source file. This time read the map file generated by the linker with the assembler's a option. If the I or D options are specified, the parameters at this stage must be the same as those of the first assembly.
The following descriptions assume that a map file has already been generated.
as103 -l -a main.map sub.asm
In the above example all files exist in or are output to the current directory. The source file (sub.asm) is assembled using a map file (main.map), generating a list file (sub.lst).
as103 -l -Lc -Lm -a main.map -D MODE prog1.asm
The above example assembles the source file (prog1.asm) in the current directory using a map file (main.map), generating a list file (prog.lst). Assembly will be performed assuming that the identifier MODE has been defined for conditional assembly directives (ifdef). Source statements of unfulfilled conditions and macro expansion source will not be output.
82 Operation Examples
Page 95

Chapter 6 Using Linker

6
Page 96
Chapter 6 Using Linker
P
P
P
le

6.1 Purpose of This Chapter

This chapter explains how to use all the options provided by the linker. The linker reads relocatable object files output by the assembler, outputs an executable format file, and if specified by option outputs a map file containing link information. If optimization was specified at the assembly stage, the linker will also adjust code such that it outputs optimal code for conditional and unconditional branch instructions. In addition, the linker also resolves forward references.
For programs in section address format, the start address of each section is specified when linking. The linker links relocatable object files by section in the order specified by the link command, and outputs an executable format file.
Relocatable Object Files Executable Format Fi
0x00000000
sectionA
Start Addresses
ROGRAM1.RF
sectionB
sectionC
ROGRAM2.RF
sectionB
sectionB
ROGRAM3.RF
sectionA
sectionA=0x00000000 sectionB=0x00000000
sectionC=0x00000000
0x40000000
Linker
0x80000000
sectionA
PROGRAM1
sectionA
PROGRAM3
sectionB
PROGRAM1
sectionB
PROGRAM2
sectionB
PROGRAM3
sectionC
PROGRAM2
Figure: 6-1 Link Model of Section Address Format
84 Purpose of This Chapter
Page 97

6.2 Starting Linker

The linker is started by entering a command name and parameters, just as for other MS-DOS external commands. The parameters are linker options and names of files to be linked.
The command name differs depending on the device being used. This chapter uses the terminology of ld103 as is general format.
General format of commands
Below is the general format of the command to use when starting the linker.
ld103 [options] relocatable_object_filename ... [library_filename]
Contents of brackets [ ] may be omitted. Ellipses (...) indicate item may be repeated.
Chapter 6 Using Linker
Specifying options
Except for the @ option, an option starts with a hyphen (-) as the options specifier, followed by a character that indicate the particular option.
-g
The @ option is not preceded by hyphen. Option specifications are case sensitive, so upper case and lower case letters must be specified
correctly.
-Ed
Single-character options not accompanied by parameters can be specified as multiple characters following the slash (/) or hyphen (-) option specifier. The order is optional.
-jmg
If you want to separate multiple options, delimit them with spaces.
-j -m -g
When an option is accompanied by a parameter and other options are to follow, add a space after the parameter, and follow with the slash (/) or hyphen (-) option specifier.
-o main.ex -gm
Starting Linker 85
Page 98
Chapter 6 Using Linker
Parameters can be specified right after the option character or separated by one space.
-T@CODE=80000000 or -T @CODE=80000000
When options are omitted, assembly will be performed in accordance with the default interpretations built in to the assembler. Refer to section 6.3, "Command Options," for default interpretations
NOTE: When specifying multiple files, separate them with spaces. Files without path
specifications are assumed to be in the current directory. The map file and executable file are always generated in the current directory regardless of any path specifications on the relocatable object files. The default names for the executable file and the map file are m103.ex and m103.map, respectively. The o option is available for creating the executable file in a directory other than the current directory. The map file is created in the same directory as the executable file.
86 Starting Linker
Page 99
Summary of Options
Option Type Symbol Description
Output file options o filename Specify the path name and file name of the
Error message options j Output error and warning messages in
Chapter 6 Using Linker
Table 6-1 Linker options
executable format file to be output.
m Output a map file
Japanese.
Je Output error and warning messages in
English.
Js Output error and warning messages in
Japanese using Shift JIS encoding.
Jj Output error and warning messages in
Japanese using JIS encoding. e Output error and warning messages in English W number Do not output warning messages of the
specified number. Refer to chapter 10, "Error
Messages," for warning messages and their
corresponding numbers. Wall Do not output any warning messages.
Program generation options
g Output debug information to the executable
format file. T section=address Specify the start/end addresses of a start
address [,end address]section (section group). r Output an executable format file even if errors
are detected. En Do not output symbol table within the
executable format file. Ed Enable output of DATA sections to the
executable format file.
Library file options l library_filename Specify a library file.
L path_name Specify a path name for library files.
Instruction RAM options
OVL ID_number section=address
Specify starting address for section in
instruction RAM. PUT extra_symbol=address Specify address for extra symbol.
Other @filename Specify a parameter file.
h Output help information to the screen. v Display the linker’s version number on the
console.
Starting Linker 87
Page 100
Chapter 6 Using Linker

6.3 Command Options

This section describes the options used by the linker. The linker has many options for controlling output file specifications and the information written to files. The linker reads multiple relocatable object files, links them into one, and creates an executable format file.
If optimization was selected at the assembly stage, the linker will output the optimal machine language code for conditional and unconditional branch instructions, regardless of the mnemonics defined in the source file.
In addition, the linker resolves the values of forward-referenced symbols and undefined operands.
88 Command Options
Loading...