I am currently doing a computer course where I have to run assembly inside of C++. In my class, everyone is running it in Windows and they have no problem running the code (I was able to do it on Windows too). When I execute the code on my Mac using Xcode, I get XC_BAD_ACCESS (code=EXC_I386_GPFLT)
which I think means that macOS is protecting me from running system calls.
When debugging the line that crashes the program, I think it is the call printf
line that is giving me the error as the code executes and completes successfully.
Here is the code:
#include <iostream>
#include <stdio.h>
using namespace std;
char format[] = "%s %s\n";
char hello[] = "Hello";
char world[] = "world";
int main()
{
__asm
{
mov eax, offset world
push eax
mov eax, offset hello
push eax
mov eax, offset format
push eax
call printf
pop eax
pop eax
pop eax
}
}
To get this 32-bit code to work on my 64bit Mac, on Xcode, I went to Build Settings -> Architectures
and selected 32-bit Intel
in order to compile it.
How would I fix the EXC_I386_GPFLT
runtime error on my Mac running 10.13.2?
Note: In Xcode, I created a macOS Command Line Tool.
Edit: I forgot to say that I tried disabling rootless (SIP) and ran Xcode when logged into the root user. That still did not work.