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.

  • Intel-x86
  • ARM

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 Intel-x86 view - other views are ARM

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 Intel x86 processor.

We will use the gcc compiler.

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

gcc -m32 -c 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, Intel 80386, 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

Registers

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:

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