Welcome to your Raspberry Pi linux terminal. If you're here, you've successfully connected via SSH using ssh [email protected] -p 5022
. If you're unsure about the setup process, please refer to the previous notes on setting up QEMU for ARM here.
Open the helloworld.s
file in the nano editor:
nano helloworld.s
Here's the helloworld.s
ARM assembly code:
.global _start
_start:
MOV R0,#1
LDR R1,=message
LDR R2,=len
MOV R7,#4
SWI 0
MOV R7,#1
SWI 0
.data
message:
.asciz "radhe radhe \n"
len = .-message
.global _start
: Marks the_start
label as global, making it visible to the linker._start:
: The entry point of our program.MOV R0,#1
: Moves the value1
into registerR0
, which is used for file descriptor (stdout).LDR R1,=message
: Loads the address of themessage
label into registerR1
.LDR R2,=len
: Loads the address of thelen
label into registerR2
.MOV R7,#4
: Moves the value4
into registerR7
, which is the system call number for 'write'.SWI 0
: Triggers an interrupt to invoke a system call..data
: Indicates that what follows is data (not code).message:
: A label marking where our message starts..asciz "radhe radhe \n"
: Defines a null-terminated string.len = .-message
: Defines the length of our message.
Compile the assembly code into an object file:
as helloworld.s -o helloworld.o
Link the object file to create an executable:
ld helloworld.o -o helloworld
Verify that all files are present:
ls
Run your executable:
./helloworld
You should see the output:
radhe radhe