Write and compile "Hello World!"

Let's start with a simple C program, and use the armclang and armlink tools to compile and generate an executable image.

  1. In your command-line terminal, use your favorite editor, for example, vi, to create a new file called hello_world.c with the following contents:

    #include <stdio.h>
    int main(void) {
      printf("Hello World\n");
      return 0;
  2. Compile the C code to object code with armclang:

    $ armclang -c -g --target=aarch64-arm-none-eabi hello_world.c

    This command tells the armclang compiler to compile hello_world.c for the Armv8-A architecture and generate an ELF object file hello_world.o.

    The options used in this command are:

    • -c tells the compiler to stop after compiling to object code. We will perform the link step to create the final executable in the next step.
    • -g tells the compiler to include debug information in the image.
    • --target=aarch64-arm-none-eabi tells the compiler to target the Armv8-A AArch64 ABI.
  3. Create an executable image by linking the object using armlink. This generates an ELF image file named __image.axf:

    $ armlink hello_world.o

Because we have not specified an entry point, when you run this image the entry point defaults to __main() in the Arm libraries. These libraries perform a number of setup activities, including:

  • Copying all the code and data from the image into memory.
  • Setting up an area of memory for the application stack and heap.
  • Branching to the main() function to run the application.

This diagram illustrates the code startup sequence that shows how control passes from the C library to your code:

Write and compile hello world diagram.

Previous Next