I'm trying to write Intel x86 Assembly code on macOS similarly to the following screenshot:
This screenshot is taken from my professor's Visual Studio application, where he writes assembly. He's also stated that this wouldn't work on a Mac. To do this, I need the C++ Console app on Visual Studio, which the Mac version does not offer.
I've tried to circumvent this issue by trying to compile it on Visual Studio Code on my Mac (M2 Chip), and also following this reference.
My current code snippet looks like this:
#include <stdio.h>
#include <stdlib.h>
int main(void)
{
int num = 10;
asm(
"mov eax, num\n"
"add eax, 12\n"
"mov num, eax"
);
return 0;
}
However, upon running this through g++ test.cpp
, I receive the following errors:
"mov eax, num\n"
^
<inline asm>:1:6: note: instantiated into assembly here
mov eax, num
^
test.cpp:10:11: error: invalid operand for instruction
"add eax, 12\n"
^
<inline asm>:2:5: note: instantiated into assembly here
add eax, 12
^
test.cpp:11:11: error: invalid operand for instruction
"mov num, eax"
^
<inline asm>:3:5: note: instantiated into assembly here
mov num, eax
^
Any ideas on how to solve this issue? (Note: not sure if this is relevant to the problem but I've also installed nasm
through brew install nasm
)