Migrating some GCC inline assembler constructions

Technical Note 86655

Architectures:

ARM

Component:

compiler

Updated:

11/6/2015 1:15 PM

Introduction

This Technical Note discusses migration from GCC inline assembler to IAR Embedded Workbench for ARM. This Technical Note applies to ARM7/9 devices, not to Cortex devices.

Acknowledgment

These examples have been written by Mr. Ivan Paulik, Pasat, Bratislava, Slovakia, Europe. We are most grateful that he shares his findings with IAR Embedded Workbench for ARM users.

 

Background

Now and then there are users requesting that IAR makes a "GCC to IAR Embedded Workbench for ARM Migration Guide". This might seem to be trivial task (as IAR have written other Migration Guides), but it is not trivial - as there is no "one single GCC compiler" we are not able to cover all GCC variants.

Suggestion

The most different area between GCC and IAR Embedded Workbench for ARM is Inline Assembler and such constructions (and some other issues) will be commented in this Technical Note (and in the attachment). The goal is that the 9 examples + comments should cover the issues that are most different between GCC and IAR Embedded Workbench for ARM, and that other issues can be sorted out by the developer that performs the migration.

General comment

The GCC compiler seems to give the user more responsibility to the user, where IAR Embedded Workbench for ARM instead uses keywords, intrinsic functions and/or options for covering the same construction in the application.

The examples

EXAMPLE 1 -- Code referencing to one of the MCU registers.

Example 1.pdf

Please rewrite such constructions without reading/using the general registers. As noted in the example, there is great risk that IAR C/C++ Compiler for ARM (ICCARM) will re-use register R0 and thus create a run-time error.

EXAMPLE 2 -- Using SWI instruction.

Example 2.pdf

Replace the GCC construction with the IAR Systems C/C++ Compiler for ARM keyword __SWI.

EXAMPLE 3 -- Calling a function with parameters from inline assembler.

Example 3.pdf

This should not be used in ICCARM as the use of inline assembly should be minimized in order to make the compile more efficient.
The IAR Systems suggestion is to rewrite the inline assembly as a real assembly function in an assembly file.

EXAMPLE 4 -- Using a function without a "prolog" and "epilog".

Example 4.pdf

There are great risks in keeping the GCC construction. The IAR Systems suggestion is to rewrite the inline assembly as a real assembly function in an assembly file.

EXAMPLE 5 -- Using packed data structures.

Example 5.pdf

This is describes a change of syntax from GCC to IAR Systems C/C++ Compiler for ARM.

EXAMPLE 6 -- Reference to segment start, end, etc.

Example 6.pdf

Rewrite with the use of the IAR Systems C/C++ Compiler for ARM section operators.

EXAMPLE 7 -- Creating own "prolog" and "epilog" to a function without implicit entry and return parameter handling.

Example 7.pdf

Remove the GCC constructions and use the Interwork option instead.

EXAMPLE 8 -- Using interrupt functions.

Example 8.pdf

This is describes a change of syntax from GCC to IAR Systems C/C++ Compiler for ARM.

EXAMPLE 9 -- Aligning data structures.

Example 9.pdf

This is describes a change of syntax from GCC to IAR Systems C/C++ Compiler for ARM.

Note:
This Technical Note does not cover all GCC-to-IAR Embedded Workbench for ARM conversion issues, but is it at least a starting point for the migration.

 

All product names are trademarks or registered trademarks of their respective owners.

We do no longer support Internet Explorer. To get the best experience of iar.com, we recommend upgrading to a modern browser such as Chrome or Edge.