5

Possible Duplicate:
How do I do inline assembly on the IPhone?

I am running xcode4.2.1, can I do in line assembly i.e. __asm in the code?

Community
  • 1
  • 1
jdl
  • 6,151
  • 19
  • 83
  • 132

1 Answers1

4

It's just a matter of using an inline specified and an asm() call:

inline void myFunction() {
    __asm__(//asm goes here);
}

CLANG does use a similar but different form of ASM though (it's still pretty darn compatible with GAS, which can be read about here

CodaFi
  • 43,043
  • 8
  • 107
  • 153
  • 2
    It's a little more than that, if you don't specify the inputs and outputs, your code will be at the mercy of the optimizer. Bad things can and WILL happen to your inline assembly: it will be shuffled around, clobber random variables, and it can even be deleted entirely by the optimizer. – Dietrich Epp Jul 11 '12 at 04:44
  • Yep. He's gonna have a helluva time fighting CLANG. If you're worried about it, just put the volatile keyword in. That should cripple most of the optimizations. – CodaFi Jul 11 '12 at 04:46
  • Sorry, but that's wrong too. Volatile will prevent the compiler from moving or removing it, but it won't prevent the compiler from clobbering variables or doing other random nonsense. See http://stackoverflow.com/questions/8891139/why-is-this-inline-assembly-not-working/8891190#8891190 – Dietrich Epp Jul 11 '12 at 14:25
  • Hey, I said cripple, not remove. – CodaFi Jul 11 '12 at 18:41
  • But it doesn't affect very many optimizations, it just prevents two things: code movement from one side of the assembly to the other, and wholesale deletion. The first optimization is something you usually want, so disabling it is bad. The second optimization won't happen if you label your registers correctly in the first place. So there's no point, it's just a bunch of voodoo magic that programmers sprinkle in their assembly because it worked for them, once, on one compiler. Your asm is almost certainly NOT `volatile` and labeling it as such is wrong. – Dietrich Epp Jul 11 '12 at 19:39