Page 120 - ARM 64 Bit Assembly Language
P. 120
106 Chapter 4
svc Supervisor Call.
In Linux, the system calls are documented in section two of the online manual. Each system
call has a unique id, which may vary from one computer architecture to the next, or from op-
erating system to another. On Linux, it is generally better to make system calls by using the
corresponding C library function, rather than calling them directly from assembly. This is be-
cause the C library function may perform additional work before or after making the system
call. For instance, the exit library function may invoke other functions to cleanly shut down
the program before it performs the exit system call.
4.3.3.1 Syntax
svc <syscall_number>
• The <syscall_number> is encoded in the instruction. The operating system may exam-
ine it to determine which operating system service is being requested.
• In Linux, <syscall_number> should always just be zero. The system call number is
passed in x8 and six other parameters can be passed in on x0-x5.
4.3.3.2 Operations
Name Effect Description
svc Request Operating System Service Perform software interrupt.
4.3.3.3 Example
This example leverages the write system call to print a message without using any C stan-
dard library functions, like printf:
1 .section .rodata
2 msg: .string "She Sells Sea Shells By The Sea Shore\n" // 39 bytes
3 .text
4 .type main, %function
5 .global main
6 // the following code asks the operating system
7 // to write some characters to standard output
8 main:
9 stp x29, x30, [sp, #-16]!
10
11 mov x0, #1 // file descriptor 1 is stdout
12 adr x1, msg // load address of data to write
13 mov x2, #39 // load number of bytes to write
14 mov x8, #64 // syscall #64 is the write() function
15 svc #0 // invoke syscall