Syscall Calling Conventions on x86-64, ARM64 and RISC-V
Compare Linux system calls on x86-64, ARM64 and RISC-V: the trap instruction, number register, argument registers and the same hello program in each.

A system call is the same idea on every CPU, but the details are different on each one: which instruction enters the kernel, which register holds the call number, which registers carry arguments, and what the call numbers themselves are. If you write assembly, a runtime, a tracer or a seccomp filter, you must get these right for each target. This post compares the three architectures most Linux developers meet today, x86-64, ARM64 (AArch64) and 64-bit RISC-V, using a Linux 6.12 kernel, and ends with the same "hello" program written for each.
The comparison in one table
| x86-64 | ARM64 | RISC-V 64 | |
|---|---|---|---|
| Trap instruction | syscall | svc #0 | ecall |
| Call number | rax | x8 | a7 |
| Arguments 1 to 6 | rdi, rsi, rdx, r10, r8, r9 | x0 to x5 | a0 to a5 |
| Result | rax | x0 | a0 |
| Registers the kernel may clobber | rcx, r11 | none beyond the result | none beyond the result |
write | 1 | 64 | 64 |
exit | 60 | 93 | 93 |
exit_group | 231 | 94 | 94 |
getpid | 39 | 172 | 172 |
The authoritative source for this is the syscall(2) manual page, which has a table of the registers for each architecture, and the kernel's own entry code under arch/<arch>/. The numbers come from arch/x86/entry/syscalls/syscall_64.tbl for x86-64 and from the shared table in include/uapi/asm-generic/unistd.h for ARM64 and RISC-V.
Why ARM64 and RISC-V share numbers
ARM64 and RISC-V were added to Linux after the old system calls had accumulated historical baggage. Neither architecture has the legacy interfaces such as open, fork, dup2 or stat in the kernel; they use only the modern replacements (openat, clone, dup3, fstatat). Both use the generic table in asm-generic/unistd.h, which is why their numbers match.
x86-64 predates that clean-up and keeps its original numbering, with the legacy calls still present. The order of the numbers there reflects the history of the i386 interface, not any logic. The practical effect is that a table of numbers is only valid for one architecture, and a program that hard-codes 1 for write works on x86-64 and writes to the wrong place elsewhere.
x86-64 in detail
The syscall instruction does three things in hardware: it copies the address of the next instruction into rcx, copies the flags register into r11, and jumps to the kernel entry address stored in the LSTAR register. That is why rcx and r11 are clobbered by every system call. The kernel return path uses sysretq, which restores the instruction pointer and flags from those two registers.
The fourth argument is r10, not rcx as in the C calling convention. The mismatch is a direct consequence of syscall overwriting rcx: the kernel could not receive a value in a register the instruction destroys. Glibc wrappers copy rcx to r10 before the trap.
.intel_syntax noprefix
.globl _start
.text
_start:
mov eax, 1
mov edi, 1
lea rsi, [rip + msg]
mov edx, 6
syscall
mov eax, 60
xor edi, edi
syscall
.section .rodata
msg: .ascii "hello\n"as -o hello_x86_64.o hello_x86_64.s
ld -o hello_x86_64 hello_x86_64.o
./hello_x86_64helloARM64 in detail
On ARM64 the trap is the supervisor call, svc #0. The immediate is ignored by Linux; the kernel reads the number from x8 instead. The CPU takes a synchronous exception from the lower exception level (EL0, user) to EL1, where the vector table sends it to the code that handles system calls. Linux's handler is el0_svc in arch/arm64/kernel/syscall.c. Only x0 carries the result, and the kernel preserves all other registers that the AArch64 calling convention does not allow it to change, so there are no rcx-style surprises.
.globl _start
.text
_start:
mov x0, #1 // fd = stdout
adr x1, msg
mov x2, #6
mov x8, #64 // write
svc #0
mov x0, #0
mov x8, #93 // exit
svc #0
.section .rodata
msg: .ascii "hello\n"aarch64-linux-gnu-as -o hello_arm64.o hello_arm64.s
aarch64-linux-gnu-ld -o hello_arm64 hello_arm64.ohelloThe output shows the program running on an ARM64 machine or under an emulator; the program text is what matters here. The tool names assume a cross-binutils package for AArch64 on an x86-64 host.
RISC-V in detail
RISC-V uses ecall, "environment call", which raises a trap from user mode to the next higher privilege level. Linux runs in supervisor mode and handles the trap in arch/riscv/kernel/entry.S. The number goes in a7, the arguments in a0 to a5, and the result comes back in a0. The register names a0 to a7 are the ABI names for x10 to x17.
.globl _start
.text
_start:
li a0, 1
la a1, msg
li a2, 6
li a7, 64
ecall
li a0, 0
li a7, 93
ecall
.section .rodata
msg: .ascii "hello\n"riscv64-linux-gnu-as -o hello_riscv64.o hello_riscv64.s
riscv64-linux-gnu-ld -o hello_riscv64 hello_riscv64.ohelloThe listings carry no comments because the comment character differs between the three assemblers; the ARM64 one uses // and the others use #. Compare the three listings. The structure is identical: load the file descriptor, the address and the length; load the number; trap; then repeat for exit with a status of zero. Only the registers, the trap instruction and the numbers change.
Return values and errors
On all three architectures covered here, an error is reported as a negative number in the result register, in the range -4095 to -1, and the C library converts it to errno. This is the same convention described in the previous posts in this cluster. Some other architectures differ: MIPS and Alpha return a positive error number and set a separate error flag in a register, and the glibc wrapper reads the flag. That difference is handled below the C library and is invisible to ordinary programs, but it matters if you write raw assembly for those targets.
Differences that trip people up
Three details cause most mistakes when porting code between these architectures.
Missing legacy calls.
open,stat,fork,pipe,dup2andgetdentsdo not exist on ARM64 or RISC-V. Useopenat,newfstatat,clonewith fork flags,pipe2,dup3andgetdents64. A seccomp filter or an strace script keyed on x86-64 names will not match.**Argument order for
clone.** The fourth and fifth arguments ofcloneare swapped on some architectures. Theclone(2)manual page documents this, so check it before writing a raw call.Seccomp architecture field. A seccomp filter sees an
archfield instruct seccomp_dataalong with the number. A filter written for x86-64 numbers must checkarchfirst, or it misreads the number on a different ABI, including the 32-bit compat interface on the same machine.
Reading the numbers from your own system
You do not need to memorize the tables. The kernel headers on a development machine contain the numbers for the architecture it targets:
grep -E '__NR_(write|exit_group|getpid) ' /usr/include/asm/unistd_64.h#define __NR_write 1
#define __NR_getpid 39
#define __NR_exit_group 231On an ARM64 or RISC-V machine, the same command against its headers prints the numbers 64, 172 and 94. The header path varies by distribution and by cross-compiler sysroot. In C, use the SYS_ constants from <sys/syscall.h> instead of numbers, so the code compiles correctly for each target.
When portability is the goal
For portable code, do not issue the trap yourself. Use the C library, or syscall() with the SYS_ constants, so the compiler and library choose the right registers and numbers. Write the architecture-specific code only when there is no C library, as in a minimal static program or a runtime that ships its own system call layer, and keep one small file per architecture so each stays easy to read.


