Compile the assembly directly in Xcode

What is the best way to compile assembly code in xcode. I have assembly files that are generated. Is there a way that I can simply include the .s file directly in the c code that I have. Or do I need to start the preprocessor first, which will generate a .o file that I can link to my files. If so, how do you do it in Xcode.

+3
source share
4 answers

If you can post the exact compiler error, then xcode spits out, then I could find a better solution, but I guess you forget to add the _ you prefix to the assembly.

 .globl _add_in_asm
_add_in_asm:
      add r0,r0,#1
      bx lr

Now in the source file C

#include <stdio.h>

extern int add_in_asm(int i);  

int main(int argc, char* argv[]) {
     printf("result:%i\n", add_in_asm(10));
     return 0;
}

The program should print

 result:11
+3
source

, , Mach-O . @A Person , .

-

extern int add_in_asm(int i);

ASM:

_add_in_asm
0

Google, , (Xcode 7.3.1, )

  • Xcode , ,

    .globl _add_in_asm .align 4 _add_in_asm: add r0,r0,#1 bx lr

  • AppDelegate.m

    include <stdio.h>

    in the application - (BOOL): (UIApplication *) application doneFinishLaunchingWithOptions: (NSDictionary *) launchOptions {// Override the point to configure after the application starts.

    extern int add_in_asm(int i); printf("result:%i\n", add_in_asm(10));

Having said that, and after it was successfully launched, it does not work after I close Xcode and restart it ... well, you need to use a real device and when you restart it will try to use the emulator !!!!

`    
/Users/xxx/Documents/myMac-git/testasm/my-testasm.s:18:11: error: invalid operand for instruction
  add r0,r0,#1
      ^
/Users/xxx/Documents/myMac-git/testasm/my-testasm.s:19:7: error: unrecognized instruction mnemonic
  bx lr
  ^
Command     /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang failed with exit code 1

`

If you see the message above, use real devices!

0
source

Source: https://habr.com/ru/post/1716981/


All Articles