0

This question is for educational purpose only. I want to know the way to include an inline assembly code (I am using Xcode, with i7 Intel processor) in a C source code.

For example:

main(){
int a = 2, b = 3, c = 0;

/*
*Sum c = a + b implemented using assembly
*/
{
mov eax, ??? (a)
mov ebx, ??? (b)
bla bla bla...
}

return 0;
}
phoenix
  • 3,069
  • 3
  • 22
  • 29
shogitai
  • 1,823
  • 1
  • 23
  • 50
  • 1
    Search for and read about *inline assembly in clang* (it's compatible with GCC inline assembly by the way). – Some programmer dude Jan 31 '16 at 10:18
  • For gcc, checkout --> http://ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html – Haris Jan 31 '16 at 10:19
  • 1
    Also see: [using assembly code inside Objective c program (Xcode)](http://stackoverflow.com/questions/25326307/using-assembly-code-inside-objective-c-program-xcode) – l'L'l Jan 31 '16 at 10:33

1 Answers1

2

Read the clang manuals (clang is the compiler used by xcode).

E.g., see here: http://clang.llvm.org/compatibility.html#inline-asm

ul90
  • 762
  • 3
  • 8
  • 3
    Link only answers are discouraged. Better add some information in your answer or make it a comment. – Haris Jan 31 '16 at 10:23
  • @Haris: in this case, RTFM really is the best answer. There's no "simple" way to explain how to use inline asm. Although there are some good links specifically about inline asm in the x86 tag wiki: http://stackoverflow.com/tags/x86/info. Most of the points apply generally, not just to x86 but to GNU inline asm syntax for any architecture. – Peter Cordes Jan 31 '16 at 12:25