每个汇编代码的分段错误 [英] segmentation fault at every assembly code
问题描述
我正在尝试在树莓派上学习汇编.但是我无法开始,我编写的每个代码都出现了段错误".
I'am trying to learn assemly on raspberry pi.But I couldn't get started, every code i write gets "Segmentation Fault".
.text
.global _start
_start:
MOV R0, #2
SWI 0
此代码出现分段错误.即使我删除了MOV行,它也会出现分段错误.
This code gets segmentation fault. Even if I delete the MOV line it gets segmentation fault.
推荐答案
尝试:
bx lr @ Exit if use gcc as linker
或
mov r7, #1 @ Exit if use ld as linker
svc #0 @ Exit if use ld as linker
某些版本使用 swi
,使用 ld
作为链接器的 svc
取得了成功.如果使用 gcc
作为链接器,则 lr
寄存器将返回OS.确保将lr寄存器保存在代码的开头,并在 bx lr
之前将其恢复.有关更多详细信息,请参见将C函数与ARM汇编一起使用.
Some version use swi
, I have success with svc
using ld
as the linker. If you use gcc
as the linker, the lr
register has the return to OS. Be sure to save the lr register at the beginning of your code and restore it before the bx lr
. See Using C functions with ARM assembly for more details.
这篇关于每个汇编代码的分段错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!