我正在摆弄我的新树莓派,而且我对组装还很陌生。我已经在 Google 和 SO 上搜索过这个问题的解决方案,这是我最接近运行程序的方法。
main.s(注释来自网上的解释)
.section .text
.global _start
_start:
mov x0, #0 // return value 0 for success
mov x7, #1 // 1 is exit in the vector table
svc 0 // execute the system call to exit the program
然后我使用 as main.s -o main.o
进行汇编,并使用 ld main.o -o main
进行链接。使用 ./main
运行输出“非法指令(核心转储)”。
这是运行 ARM Arch Linux 的 Raspberry Pi Model B在 64 位四核 ARM Cortex-A53 上。
目标:只用as
和ld
编译并链接一个ARM汇编程序,并成功退出
最佳答案
在 syscall
的手册页中,它指出系统调用的 arm64 架构调用约定是:“argument: x8”和“instruction: svc#0”。在 this github project ,“exit”的系统调用参数定义为“93”。因此,这是一个仅使用 as
和 ld
编译的工作、退出和成功的 arm 程序...
.section .text
.global _start
_start:
mov x0, #0 // exit with status 0
mov x8, #93 // svc argument goes in x8, and the argument for 'exit' is 93
svc #0 // executes a syscall in arm64
Another answer在 SO 上有关于系统调用的有用信息
关于assembly - Raspberry Pi 3 Model B ARM assembly 非法指令(Core Dumped),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48918110/