每个汇编代码的分段错误 [英] segmentation fault at every assembly code

查看:22
本文介绍了每个汇编代码的分段错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试在 raspberry pi 上学习汇编.但我无法开始,我编写的每个代码都会出现分段错误".

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆