GCC supports CodeWarrior-style inline asm code. To enable this support, you add the following flag to your build settings:
-fasm-blocks |
When you import a CodeWarrior project that uses inline asm into Xcode, this flag is not set automatically, so you will have to add it yourself. You can do so with the following steps:
Select a target in the project window.
Open an inspector window like the one shown in Figure 1-3 by clicking the Info button or choosing File > Get Info.
Select the Build pane.
If the GNU C/C++ Compiler settings aren’t visible, select GNU C/C++ Compiler from the Collection menu.
Click the checkbox in the Value column next to the CodeWarrior-Style Inline Assembly setting.
Important: There is a setting Allow 'asm', 'inline', 'typeof' in the Language Settings in the Build pane. This setting, which is enabled by default, is not related to CodeWarrior-style inline asm support. It governs the use of the old-style GNU asm statements, which are not actually part of the ISO standard.
In general, the GCC implementation works the same as the CodeWarrior implementation, and any discrepancies you note should be reported as bugs (see “Feedback and Mail List”). For example, if your project contains hand-tweaked asm code, it should work correctly in the new project, unless your code specifically targets CFM-related features. (CFM refers to the executable architecture supported by the Code Fragment Manager in Mac OS 9.)
Function calls, such as bl foo, don’t currently work, and are treated as though foo is a label whose definition is missing.
Calling conventions are generally the same as for CFM, but global variables are not available through the TOC register r2. For instance, in CFM, if aglob is a global, then lwz aglob(r2) works to get the value of aglob into r3. The Mach-O equivalent is complicated, involving multiple internal labels, and at present can’t be handled with inline asm.
GCC passes the inline asm through to the assembler and doesn’t interpret it, so any errors reported from the asm code come from the assembler. In unusual cases, such as when a typedef has the same name as an op code, GCC may parse the code differently from CodeWarrior. For example, the code in listing Listing 1-1 will result in warnings and a body with one nop if using CodeWarrior, and a body with two instructions (mr r1,r2 and nop 0 if using GCC. (This should probably be considered a bug in GCC’s implementation.)
Listing 1-1 A typedef with the same name as an op code
typedef int mr; |
asm int foo() |
{ |
mr r1,r2; |
nop |
} |
For a related issue, see “Inlining Thresholds.”
Last updated: 2006-10-26