小程序对有兴趣学习arm64汇编可作为参考
该程序在CentOS Linux release 7.2.1603 (AltArch) 版本上验证通过:
# cat /etc/redhat-release
CentOS Linux release 7.2.1603 (AltArch)
# file hello
hello: ELF 64-bit LSB executable, ARM aarch64, version 1 (SYSV), statically linked, not stripped
# ./hello
Hello, ARM!
源码如下:
// as -o hello.o hello.S
// ld -o hello hello.o
// ./hello
// http://deker.ro/index.htm
.text //code section
.globl _start
_start:
mov x0, 0 // stdout has file descriptor 0
ldr x1, =msg // buffer to write, ‘=’ indicates it’s ldr pseudo-instruction
mov x2, len // size of buffer
mov x8, 64 // sys_write() is at index 64 in kernel functions table
svc #0 // generate kernel call sys_write(stdout, msg, len);
mov x0, 123 // exit code
mov x8, 93 // sys_exit()