Hello world

As a first task, we analyse a small Hello world program, written in C. We generate assembly code from the C code, and use the generated assembly code as a way to understand more about the underlying hardware. Our goal is to understand the instruction set for the chosen processor.

The program and its instructions

The C-program that we will use is shown in Figure 5.

/* A simple C program */ 

/* include stdio for printout purposes */ 
#include <stdio.h>

/* main function */ 
int main(void)
    printf("Hello from a C program\n");
    return 0; 

Figure 5. A C-program for printing the string "Hello from a C program".

This the ARM view - other views are Intel-x86

The program in Figure 5 is supposed to be stored in a text file, named hello_c.c.

Using a C-compiler, instructions for the processor residing inside the computer can be generated. The compiler generates instructions for the particular processor used. In this book we will use a computer with a 32-bit ARM Cortex-A8 processor.

We will use the gcc compiler.

The following command can be used to compile the code in Figure 5:

arm-none-eabi-gcc -c -mcpu=cortex-a8 hello_c.c

The result of the compilation is an object file. We can inspect the format of this file by giving the command file hello_c.o. The result of giving this command is that a message informing about the type of the file is printed. The message starts with

hello_c.o: ELF 32-bit LSB relocatable, ARM, version 1 

which shows that the file is of type ELF.

Read more

More about Instructions

Here we need references to good books and also to the official manuals.

Read more


Here we need to mention also the processor modes! Since different modes exhibit different sets of registers to the programmer (or to the compiler)

These are the registers: In user mode we have: r0 to r15, special namings are sp for r13, lr for r14, and pc for r15

Read more

Memory Access

Here we will describe how memory is accessed, using different types of instructions.

Read more

Hello world deciphered

Now we can digest the hello world assembly code.

Read more