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

Choose a common default radix for coding numbers, constant values, strings, etc.

Comment statements

Comments reveal program algorithms and processing details within a program. Choose a common format for coding comment statements.

Optimization

This Series' optimizations apply to unconditional branches, data transfer instructions, arithmetic instructions, logical instructions, bit manipulation instructions, and user-defined instructions.

Unconditional branches that undergo optimization

Data transfer, arithmetic, logical, bit manipulation, and user-defined instructions that undergo optimization

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.

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 30
Image 30
Panasonic MN1030 user manual Programming style, Optimization