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 files.
CONFIG.SYS
If FILES and BUFFERS specifications 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 files that can be opened simultaneously is insufficient.
Terminology: CONFIG.SYS
This is the file that sets the MS-DOS operating environment. FILES specifies
the number of files that can be read and written simultaneously.
BUFFERS specifies 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. Firsttime 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 1Getting Started
Chapter 2Program Development Flow
Chapter 3Introduction to Operation
Chapter 4Optimization
Chapter 5Using Assembler
Chapter 6Using Linker
Chapter 7Types of Source Statements
Chapter 8Writing Source Statements
Chapter 9Writing Machine Language Instruction
Statements and Directive Statements
Chapter 10Writing Assembler Control Statements
Chapter 11Writing Macro Control Statements
1
2
3
4
5
6
7
8
9
10
11
Chapter 12List of Machine Language Instructions
Chapter 13Error Messages
Chapter 14Reading List Files
Chapter 15Using Library Manager
Chapter 16Notes on Operating Environment
Chapter 17Appendix
12
13
14
15
16
17
index
Page 8
Table of Contents
Chapter 1Getting Started
1.1 Purpose of This Chapter............................................................................................................................. 2
2.1 Purpose of This Chapter........................................................................................................................... 14
2.2 Program Development Flow .................................. .......................................................................... ........ 15
2.3 Programming with Assembler....................................................................................................... ........... 17
Chapter 3Introduction 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 4Optimization
4.1 Purpose of This Chapter........................................................................................................................... 44
4.2 Rules of Usage .............................................................................................................................. ........... 45
5.1 Purpose of This Chapter........................................................................................................................... 60
5.3.4 Program Generation Options.......................................................................................................... 78
5.3.5 Other Options................................................................................................................................. 80
6.1 Purpose of This Chapter........................................................................................................................... 84
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
8.1 Purpose of This Chapter ........................................................................................................................ 128
8.4 Character Constants........................................................................................................... .................... 133
Chapter 9Writing Machine Language Instruction Statements and
Directive Statements
9.1 Purpose of This Chapter ........................................................................................................................ 146
10.1 Purpose of This Chapter....................................................................................................................... 182
11.1 Purpose of This Chapter....................................................................................................................... 206
12.1 Purpose of This Chapter....................................................................................................................... 226
12.3.7 Other Instructions ............................................................................................................. ......... 248
Chapter 13Error Messages
13.1 Purpose of This Chapter ....................................................................................................... ............... 250
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 15Using Library Manager
15.1 Purpose of This Chapter ....................................................................................................... ............... 274
16.1 Purpose of This Chapter ....................................................................................................... ............... 298
16.2 Personal Computer Versions ............................................................................................................ ... 299
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 1Getting Started
1
Page 14
Chapter 1 Getting Started
1.1Purpose 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.2Operating Environment
This system runs on the following workstations, personal computers and compatibles.
Host machineOperating systemVersion of OS
Sun/SparcSolaris2.6 or later
PC/ATWindows98/Me/2000/XP
DOS/VWindows98/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.3File 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.4Installation
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.5Setup
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 startup 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.
keywordparameter
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.
KeywordDescription
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.
KeywordDescription
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
KeywordDescription
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.6File 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
OptionDescription
-jDisplays error and warning messages in Japanese. *1
-eDisplays error and warning messages in English. *2
-hDisplays 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
-iOutput the execution file in Intel HEX format.
-S3Output the execution file in Motorola S3 format.
-S2Output the execution file in Motorola S2 format.
S1Output the execution file in Motorola S1 format.
-ofileSpecify the file name to output
-pNo padding.
-PPadding.
-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.
OperationDefault Setting
Chapter 1 Getting Started
Message to output
Conversion method Not with a work file
Output formatIntel HEX format
PaddingNo padding
Output file nameThe same file name as EX format file but with “.hex” or “.rom” extensions.
Conversion rangeFrom 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.
OptionExtension
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.
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 2Program Development Flow
2
Page 26
Chapter 2 Program Development Flow
2.1Purpose 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.2Program 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.3Programming 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.
#defineTYPEA
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.
#defineTYPEA
[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 3Introduction to Operation
3
Page 34
Chapter 3 Introduction to Operation
3.1Purpose 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.2Files 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.3Basic 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.
globaldata_set
__CODEsectionCODE, PUBLIC, 1
main
mov0, A0
mov0xff, D0
mov0x80, D1
jsrdata_set
bramain
_DATAsectionDATA, PUBLIC, 4
data1ds4
end
program1.asm consists of a section called _CODE (attribute CODE, link type PUBLIC) and a section
called _DATA (attribute DATA, link type PUBLIC).
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 optionOption to output map file.
T optionOption 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 optionOption to output a list file.
a optionOption 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.
40000016T data_set
40000018T data_set_ loop
40000022T 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.4Assembling 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.
globalmain
globaldata_set, time_filler
_CODE_00sectionCODE, PUBLIC, 1
main
mov0, A0
mov0xff, D0
mov0x80, D1
jsrdata_set
jsrtime_filler
bramain
_DATAsectionDATA, PUBLIC, 4
data1ds4
end
30 Assembling and Linking Multiple Sections
Page 43
The contents of program4.asm are as follows.
globaldata_set, time_filler
_CODE_01sectionCODE, PUBLIC, 1
data_set
mov0, D2
data_set_loop
cmpD1, D2
bccdata_set_end
movD0, (A0)
add1, D2
add2, A0
bradata_set_loop
data_set_end
rts
_CODE_00sectionCODE, PUBLIC,1
time_filler
mov0, D2
Time_filler_loop
cmpD1, D0
bcctime_filler_end
bratime_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 optionOption to output debug information in the relocatable object file.
l optionOption 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 ***
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 ***
LocObjectLineSource
1global data_Set, time_filler
2global data_set, time_filler
3_CODE_01section CODE, PUBLIC, 1
000000004data_set
000000008A005mov0, D2
6
000000027data_set_loo
p
00000002A68cmpD1, D2
00000003C600+9bccdata_set_end
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 optionOption to output map file.
g optionOption to add debug information to the executable format file.
T optionOption 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.
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.rfprogram4.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.
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 optionOption to output a list file.
a optionOption 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 ***
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 ***
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.5Conditional 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.
#defineDEBUG
*
dat_setmacroadr, dat
movadr, A0
movdat, D0
movD0, (A0)
endm
*
_CODEsection CODE, PUBLIC,2
mainDEBUG
#ifdef
#else
#endifdat_setdata1, 0x22
_DATAsection DATA, PUBLIC, 2
data1dw0
data2dw0
dat_setdata1, 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.
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.
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.
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 4Optimization
4
Page 56
Chapter 4 Optimization
4.1Purpose 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.2Rules 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.
opton
NOTE:Optimization is off by default.
Chapter 4 Optimization
Rules of Usage 45
Page 58
Chapter 4 Optimization
4.3Usage 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.
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.
BEQLABEL
......
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
JMPLABEL
......
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.
(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 InstructionCandid ate instruction 1 Candidate instruction 2Candidate instruction 3
BLT LABELBRA LABELBGE *+5
BGT LABELBGT LABELBLE *+5
BGE LABELBGE LABELBLT *+5
BLE LABELBLE LABELBGT * +5
BCS LABELBCS LABELBCC *+5
BHI LABELBHI LABELB LS *+5
BCC LABELBCC LABELBCS *+5
BLS LABELBLS LABELBHI *+5
BEQ LABELBEQ LABELBNE *+5
BNE LABELBNE LABELBEQ *+5
BVC LABELBVC LABELBVS *+6
BVS LABELBVS LABELBVC *+6
BNC LABEL BNC LABELBNS *+6
BNS LABELBNS LABELBNC *+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 InstructionFirst Candidate Second Candidate Third Candidate
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 displacement data. The user thus obtains optimal code size without having to worry about instruction variants.
The following table shows the possibilities for optimizing data transfer, arithmetic, logical, bit manipulation, and user-defined instructions.
Table 4-10 optimization of data transfer, arithmetic, logical bit manipulation...
Source instructionFirst CandidateSecond Candidate Third Candidate
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.
opton
_TEXTsectionCODE, PUBLIC,1
sub_func
mov0, D2
cmpD1, D2
addr_setbccfunc_end
orgaddr_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 ization. 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 ***
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 conditional branch instruction.
The source list is as follows.
opton
_TEXTsectionCODE, PUBLIC,1
sub_func
mov0, D2
cmpD1, D2
addr_setbccfunc_end
orgaddr_set+128
func_end
rts
end
The final list file after assembly is shown next. LABEL exceeds the permitted branch range of BCC LABEL, 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 ***
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 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 LABEL. Note that the mnemonics and object code are different.
Chapter 4 Optimization
opt3.lst Page 1
*** PanaX series Series MN1030 Cross Assembler ***
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 final list file after assembly is shown next. Since the CALLS LABEL instruction in line four contains 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 ***
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.2Starting 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 SymbolDescription
o file_nameSpecify the relocatable object file name to be output.
lOutput a list file.
LiDo not output files included by include to the list file.
LmDo not output assembler source created by macro expansion using
Output file
LsDo not output a symbol table to the list file.
LcDo not output source statements that were not assembled due to
a map_file nameRead 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
jOutput error and warning messages in Japanese. Output will be to the
screen and when a list file is specified, to the list file
JeOutput error and warning messages in Japanese using EUC encoding to
the console and, if specified, the listing file.
JsOutput error and warning messages in Japanese using Shift JIS
encoding to the console and, if specified, the listing file.
JjOutput error and warning messages in Japanese using JIS encoding to
the console and, if specified, the listing file.
eOutput error and warning messages in English. Output will be to the
screen and, when a list file is specified, to the list file.
W numberDo 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
WallDo not output any warning messages.
I path_nameS pecify the path name of the directory that contains files specified by
include.
D identifierSpecify an identifier to be used by ifdef during conditional assembly.
gOutput debug information to the relocatable object file.
OdTurn off optimization.
OTurn on optimization.
Others
62 Starting Assembler
hDisplay a listing of available assembler options on the console.
vDisplay the assembler's version number on the console.
Page 75
5.3Command 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.1Output File Options
o file_nameSpecify 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
lOutput 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
LiDo 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
LmDo 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
LsDo 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_filenameRead 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.2Error Message Options
jOutput 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 machineCharacter coding
Sun/SparcEUC
DOS/VShi ft JIS
PC/ATnot 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 machineMessage Language
Sun/SparcEnglish
DOS/VJapanese in Shift JIS
PC/ATEnglish
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
JeOutput 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 machineMessage language
Sun/SparcEnglish
DOS/VJapanese in Shift JIS
PC/ATEnglish
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
JsOutput 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 machineMessage language
Sun/SparcEnglish
DOS/VJapanese in Shift JIS
PC/ATEnglish
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
JjOutput 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 machineMessage language
Sun/SparcEnglish
DOS/VJapanese in Shift JIS
PC/ATEnglish
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
eOutput 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 machineMessage language
Sun/SparcEnglish
DOS/VJapanese in Shift JIS
PC/ATEnglish
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 numberDo 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
WallDo 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.3Preprocessor Options
I path_nameSpecify 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 identifierSpecify 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.4Program Generation Options
gOutput 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
OTurn 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
OdTurn 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.5Other Options
hDisplay 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.
vDisplay 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.4Operation 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 6Using Linker
6
Page 96
Chapter 6 Using Linker
P
P
P
le
6.1Purpose 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 FilesExecutable 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.2Starting 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.
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 TypeSymbolDescription
Output file optionso filenameSpecify the path name and file name of the
Error message options jOutput error and warning messages in
Chapter 6 Using Linker
Table 6-1 Linker options
executable format file to be output.
mOutput a map file
Japanese.
JeOutput error and warning messages in
English.
JsOutput error and warning messages in
Japanese using Shift JIS encoding.
JjOutput error and warning messages in
Japanese using JIS encoding.
eOutput error and warning messages in English
W numberDo not output warning messages of the
specified number. Refer to chapter 10, "Error
Messages," for warning messages and their
corresponding numbers.
WallDo not output any warning messages.
Program generation
options
gOutput debug information to the executable
format file.
T section=addressSpecify the start/end addresses of a start
address [,end address]section (section group).
rOutput an executable format file even if errors
are detected.
EnDo not output symbol table within the
executable format file.
EdEnable output of DATA sections to the
executable format file.
Library file optionsl library_filenameSpecify a library file.
L path_nameSpecify 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=addressSpecify address for extra symbol.
Other@filenameSpecify a parameter file.
hOutput help information to the screen.
vDisplay the linker’s version number on the
console.
Starting Linker 87
Page 100
Chapter 6 Using Linker
6.3Command 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...
+ hidden pages
You need points to download manuals.
1 point = 1 manual.
You can buy points or you can get point for every manual you upload.