DEV Community

hextrace
hextrace

Posted on

ARM Assembly – hello world

ARM architecture was originally designed for an Acorn computer and meant Acorn Risc Machine. It has then become an independent brand for embeeded systems and actually means Advanced RISC Architecture. ARM Cores implement an additional instruction set called THUMB encoded in 16 bits.

Let's write an Hello World program in ARM:

.text
.global _start

_start:
    mov r2, #6  @ strlen
    mov r1, pc  @ load pc
    add r1, #24 @ add str offset from pc
    mov r0, #1  @ stdout
    mov r7, #4  @ nr_write
    svc 0       @ syscall

    mov r0, #0  @ exit_success
    mov r7, #1  @ nr_exit
    svc 0       @ syscall

.asciz "hello\n"    @ null terminated string
Enter fullscreen mode Exit fullscreen mode

We have one function _start known as default entrypoint in one code section .text.

Then we have two blocks, one for writing, one for exiting (optional).

Registers r0 to r3 are used for parameter passing. Register r7 holds the syscall number

Let's assemble, link and run:

root@azeria-labs-arm:~/arm/hello# make
as hello.s -o hello.o
ld hello.o -o hello
root@azeria-labs-arm:~/arm/hello# file ./hello
./hello: ELF 32-bit LSB executable, ARM, EABI5 version 1 (SYSV), statically linked, not stripped
root@azeria-labs-arm:~/arm/hello# ./hello
hello
Enter fullscreen mode Exit fullscreen mode

Awesome, this is our first step to shellcode development.

Top comments (0)