[英]simple codes in assembly language
I am new to assembly language using the Raspberry Pi. 我是使用Raspberry Pi的汇编语言的新手。 I tried to run this simple program on a Raspberry Pi 3(ARM 8086). 我试图在Raspberry Pi 3(ARM 8086)上运行此简单程序。 It does not cause an error but when I try to see the result in a terminal after compiling and running as _o example.o example.s
, gcc _o example examle.s
and ./example
. 它不会引起错误,但是当我尝试在编译并as _o example.o example.s
, gcc _o example examle.s
和./example
运行时在终端中查看结果时。 the execution result is segmentation fault, can you help me please? 执行结果是分割错误,能帮我吗?
.align 2
.text
.global main
main:
stmfd r13!, {r14}
mov r0,#1
bl print
mov r0,#2
bl print
mov r0,#3
bl print
ldmfd r13!,{pc} @ return to OS
print:
stmfd r13!, {r0-r3,r12,r14}
mov r1,r0
ldr r0, =num_str
bl printf
ldmfd r13!, {r0-r3,r12,pc}
.data
.align 2
num_str:
.asciz “%d\n”
.end
The ABI requires that the stack pointer is aligned to multiple of 8 bytes, your main
function decrements the stack pointer by 4 making it unaligned. ABI要求堆栈指针与8个字节的倍数对齐,您的main
函数将堆栈指针减4,使其不对齐。 Presumably printf
uses an instruction that requires 8 byte alignment. 大概printf
使用一条要求8字节对齐的指令。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.