macos - 将字符打印到标准输出,x86 mac
问题描述
我在 Mac 上,我正在尝试在 X86 程序集中将单个字符打印到标准输出。我没有在网上找到任何对我有用的例子——然而,这个是最接近的。通过像这样组装它:gcc -masm=intel print.asm
我得到这个输出:
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)
这是我的clang版本:
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
这是我的代码:
.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
这真是令人沮丧,我不知道如何使它正常工作。有没有人有办法解决吗?
解决方案
推荐阅读
- wcf - 我正在测试 WCF 服务和 EF 数据层,将字符串列接收为(null),但接收整数作为真实数据。为什么字符串为空?
- flutter - 如何防止 Flutter FutureBuilder 提前触发?
- java - 我可以将 java11 与弹性 beanstalk 和 tomcat 一起使用吗?
- jquery - 点点库删除文本
- algorithm - 两个水壶拼图
- react-apollo - 如何在 Prisma 2 中使用“计数”和“分组依据”?
- python - Python Django在搜索中的多个属性
- reactjs - 为什么函数组件再次通过 setCount(1) 重新渲染
- javascript - 如何从 nativescript 中的 radlistview 中删除项目?
- javascript - 这个变量范围解析是如何准确执行的?