My goal is to use Xcode (10.2-beta) to write C and Assembly for MacOS (14.1); I want to use the NASM instead of the default GNU compiler, the GAS syntax is quite horrible.
BTW, although I configured Xcode to use NASM, as you will see below, I suspect it is not using it!
I've built my project using the GNU compiler. It runs fine.
// main.c
# include <stdio.h>
int myOperation(int a, int b);
int main(int argc, char * argv[]) {
// insert logic here
int x = 10;
int y = 12;
int z = myOperation(x, y);
printf("The sum of %d and %d is %d\n", x, y, z);
return 0;
}
// assembly.s
.text
.globl _myOperation
_myOperation:
add %esi, %edi
mov %edi, %eax
ret
I installed the XCode command line tools and changed the build rules to compile NASM files. The C file is the same:
// assembly.s
.text
.globl _myOperation
_myOperation:
add edi, esi
mov eax, edi
ret
I get the following errors:
/Users/rodrigomattososilveira/projects/asm/NASM Tutorial/Tutorial_01AA/Tutorial_01AA/assembly.s:12:5: error: unknown use of instruction mnemonic without a size suffix
add edi, esi
^
/Users/rodrigomattososilveira/projects/asm/NASM Tutorial/Tutorial_01AA/Tutorial_01AA/assembly.s:13:5: error: unknown use of instruction mnemonic without a size suffix
mov eax, edi
^
Command CompileC failed with a nonzero exit code
Some of the links I've checked out:
- X86 Assembly/GAS Syntax
- Compiling NASM Assembly with Xcode in a C/C++ Project
- Xcode and NASM coding
- Writing 64 Bit Assembly on Mac OS X
- The top links suggested at the time I created this issue