首页 > 解决方案 > 将字符打印到标准输出,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

这真是令人沮丧,我不知道如何使它正常工作。有没有人有办法解决吗?

标签: macosassemblyx86-64stdoutcalling-convention

解决方案


推荐阅读