Start page1 page2 page3 page4 page5 page6 page7 page8 page9 page10
The name svc
means service and is where you call into the
operating system to get things done.
The first example in the "Hello World" program is this:
mov x0,1
adr x1,message
mov x2,12
mov x8,0x40
svc 0
We want to print a string, and we need 4 pieces of information to do that:
x0
is set to 1 because that is the
handle for standard output. If you have opened a file,
and use that handle, you would be writing to that file.x1
is set to this address.x2
is set to the length of the string. There is no 0-byte to end the string as you see in C.The x-registers are 64 bit wide. The instructions in the program
are 32 bit wide. The assembler is cheating a little bit with
the mov
-instructions. There is no room for a
64 bit value, so mov
is translated to an instruction,
where a 16-bit value is moved to the lower part of the x-register,
and the upper 64-16=48 bits are zeroed.
Sort of the same happens with the adr
-instruction, where only the
difference in addresses between the adr
-instruction and
the message is stored — this would then be relative addressing.
This works since the string is close to the instructions.
The second use of svc is this:
mov x0,0 /* status code */
mov x8, 93
svc 0
The decimal value 93 is the code for stopping the program. We should
also put the status code in register x0
. A simple 0 when
everything is fine, and some positive number to indicate errors.
If we don't set x0
to some value, then the status is
whatever is in x0
.
This status code can then be read in the line following the execution of the program.
user@rpi4:~/work $ ./hello1
Hello World
user@rpi4:~/work $ echo $?
0
Why use hexadecimal in the first example, and decimal in the second? It is just to show that you can do both.
Now change the status code to something not 0 — anything will do.
And then read it with echo $?
.
Start page1 page2 page3 page4 page5 page6 page7 page8 page9 page10
2025-06-16