Display one message using assembly code under linux os.

The source code it’s very simple.

The message it’s show using int 80 and eax with function 4.

We need the message and length of this message.

See next the source code and comments:

Posted in All, Assembler, Linux, Programming. Tagged with , , , .
  • The above source is for FASM, NASM or some other non-standard assembler for GNU/Linux.

    The standard assembler is the GNU assembler and the following is a translation to it’s syntax:

    /* the hello variable points to a null terminate string containing the words
    'hello world', followed by a newline */
    hello:
    .asciz "Hello world\n"
    /* the length of the string can be calculated by reading the current position
    and subtracting the start of the string the '.' operator represents the current
    position and hello is at the start of the string -- hence . - hello = the length
    of the string */
    length:
    .long .-hello

    .globl _start
    _start:
    /* perform function 4 write a string to a file */
    mov $4, %eax
    /* select stdout as the file to write to */
    /* (replace the 1 with 2 to write to stdout) */
    mov $1, %ebx
    /* print the contents pointed to by the hello variable */
    mov $hello, %ecx
    /* the length of the contents is stored in the length variable */
    mov length, %edx
    /* do it! */
    int $0x80

    /* perform function 1 (terminate the process) */
    mov $1, %eax
    /* tell the kernel that everything went fin */
    mov $0, %ebx
    /* do it */
    int $0x80

    /*
    to compile the program execute
    as -o hello.o hello.s
    ld hell.o -o hello

    this produces an executable which prints the message and terminates with
    success
    */

    • The source will, naturally, only work on x86s.

      • I have just x86 procesor – Athlon XP 🙂 sorry .

    • Well done. This is just one tutorial . I like both FASM and NASM. About compile and execute is also same in linux with a little diff when use many source code and libs. If you want to write one tutorial I will add it with your author title. The goal of free-tutorials.org is to maintain and show simple way to do more in a simple way. Thank you for your comment. Regards . 🙂