Start page1 page2 page3 page4 page5 page6 page7 page8 page9 page10
Use some text editor to enter the following program, and call it
hello1.s
— the extension .s
is for assembler.
.text
.global _start
_start:
/* Print a message on stdout, x0=1 */
mov x0,1
adr x1,message
mov x2,12
mov x8,0x40
svc 0
/* And exit the program */
mov x0,0 /* status code */
mov x8, 93
svc 0
message: .ascii "Hello World\n"
I prefer spaces when indenting, but tabs are fine as well.
We now need to assemble this code, link it, and run it. This is what happens on my Rpi4:
user@rpi4:~/work $ as hello1.s -o hello1.o
user@rpi4:~/work $ ld hello1.o -o hello1
user@rpi4:~/work $ ./hello1
Hello World
user@rpi4:~/work $
We first assemble the program to hello1.o
— the .o
is for object file.
Then the object file is linked to create an executable file: hello1
.
And then this file is executed. It will automatically have the execute property, but we must prefix with
the current directory, ./
, to have it executed. Yeah, it's Linux.
In the linking phase we could have combined more .o
-files and added some libraries.
We learn by playing, so I suggest you change the program, and see what happens.
x2
. It was a 12, we added 5 characters.
Change the 12 to 17, and try again.You should at this point have this small assembly program running. If not, then check if you did everything right.
On the next page I'll explain some of what goes on.
Start page1 page2 page3 page4 page5 page6 page7 page8 page9 page10
2025-06-16