This section shows how to write a simple “Hello, World” Linux application in Blackfin assembly. For details on how to actually compile this code and run it on a Blackfin board, please read the first Simple Hello World Application Example.

Due to the way data and functions are referenced differently in the binary formats FLAT and FDPIC ELF, we will present a few examples.

Note that we deliberately skim over the inner details of FDPIC ELF here. For in-depth details, please check out the FDPIC ELF page.

If you plan on writing assembly code, make sure you adhere to the Blackfin ABI.

Since the FLAT format statically links all code and data together in one object, we use absolute references for both data and functions. At runtime, the kernel will automatically process all these relocations and replace the code call _printf with call 0x412959AE.

The limitation here is that code segments cannot be shared at runtime between processes.

Since the FDPIC ELF format is designed from the ground up to share read-only sections between different processes, we need to make sure that code can be run independent of its position in memory. In order to access writable data that cannot be shared, each process needs its own table of pointers (called the GOT). In the following example we see how to access data via the GOT.

This example uses an absolute reference to the printf function; this works because the assembler/linker automatically inserts a trampoline to accessing the correct location of printf.

This example is just like the one above except for the way we call printf. Previously, we just let the assembler/linker take care of the gory details, but now for fun we'll go ahead and look up the printf function ourselves and then call it.