Skip to main content

IAR Embedded Workbench for RH850 3.20.x

Modular programming

In this section:

It is widely accepted that modular programming is a prominent feature of good software design. If you structure your code in small modules—in contrast to one single monolith—you can organize your application code in a logical structure, which makes the code easier to understand, and which aids:

  • efficient program development

  • reuse of modules

  • maintenance.

The IAR development tools provide different facilities for achieving a modular structure in your software.

Typically, you write your assembler code in assembler source files—each file becomes a named module. If you divide your source code into many small source files, you will get many small modules. You can divide each module further into different subroutines.

A section is a logical entity containing a piece of data or code that should be mapped to a physical location in memory. Use the section control directives to place your code and data in sections. A section is relocatable. An address for a relocatable section is resolved at link time. Sections enable you to control how your code and data is placed in memory. A section is the smallest linkable unit, which allows the linker to include only those units that are referred to.

If you are working on a large project you will soon accumulate a collection of useful routines that are used by several of your applications. To avoid ending up with a huge amount of small object files, collect modules that contain such routines in a library object file. Note that a module in a library is always conditionally linked. In the IAR Embedded Workbench IDE, you can set up a library project, to collect many object files in one library. For an example, see the tutorials in the Information Center.

To summarize, your software design benefits from modular programming, and to achieve a modular structure you can:

  • Create many small modules, one per source file

  • In each module, divide your assembler source code into small subroutines (corresponding to functions on the C level)

  • Divide your assembler source code into sections, to gain more precise control of how your code and data finally is placed in memory

  • Collect your routines in libraries, which means that you can reduce the number of object files and make the modules conditionally linked.