我正在编写一个简单的 x64 程序,它调用一个 C 程序来打印一个字符串。我正在使用 Mac OS X
X64:
.data
hello_world: .asciz "hello world!\n"
.globl _print_string
.globl _main
_main:
pushq %rbp
movq %rsp, %rbp
leaq hello_world(%rip), %rdi
callq _print_string
movq %rbp, %rsp
popq %rbp
C 程序:
#include <stdio.h>
void
print_string(char *str)
{
printf("%s\n", str);
}
但为什么我得到 './output' 被信号 SIGBUS(未对齐的地址错误)终止。谁能给我解释一下?
最佳答案
.s
文件的第一行切换到数据段,并且永远不会切换回来。这使得数据段中的 main
函数无法执行。
在开始编写任何代码之前,使用 .text
切换回文本段。 (或者切换到数据段并在 main
之后定义您的字符串常量。)
关于c - X64 程序集 : terminated by signal SIGBUS (Misaligned address error),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43298935/