I am on a Mac and I am trying to print a single character to stdout in X86 assembly. I have not found any examples on line that worked for me - however, this one came the closest. By assembling it like this: gcc -masm=intel print.asm
I get this output:
Undefined symbols for architecture x86_64:
"putchar", referenced from:
_main in print-c2eebf.o
ld: symbol(s) not found for architecture x86_64
clang: error: linker command failed with exit code 1 (use -v to see invocation)
Here is my clang version:
Configured with: --prefix=/Library/Developer/CommandLineTools/usr --with-gxx-include-dir=/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include/c++/4.2.1
Apple clang version 11.0.3 (clang-1103.0.32.62)
Target: x86_64-apple-darwin19.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Here is my code:
.global _main, putchar
.text
_main:
push 0x21 # put exclamation point on stack
call putchar
mov rdi, 0 # exit code of zero
mov rax, 0x2000001
syscall
This is really frustrating, I do not know how to make it work properly. Does anyone have a solution?