I am messing around with my new raspberry pi and I am fairly new to assembly. I have scoured Google and SO for a solution to this, and this was the closest I got to having a running program.
main.s (comments are from explanations I've found on the internet)
.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
I then assemble with as main.s -o main.o
and link with ld main.o -o main
. Running with ./main
outputs "Illegal instruction (core dumped)".
It's a Raspberry Pi Model B running ARM Arch Linux on a 64-bit quad-core ARM Cortex-A53.
Goal: Have an ARM assembly program compiled and linked with only as
and ld
that will exit successfully
In the man page for syscall
, it states that the arm64 architecture calling convention for syscalls is: "argument: x8" and "instruction: svc #0". On this github project, the syscall argument for 'exit' is defined as '93'. Therefore, this is a working, exiting, and succeeding arm program compiled using only as
and ld
...
.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 on SO with useful info on system calls