beta.blog

FASM: Hello World (ELF)

by on Sep.23, 2011, under Programming

This example code shows how to write a simple Linux Hello World application in flat assembler. The example code uses system calls in order to print text, therefore no additional libraries are being used. All system calls are parameterized using the CPU registers and executed with the interrupt: int 0x80

format ELF executable 3
entry start

;================== code =====================
segment readable executable
;=============================================

start:

        mov     eax,4             ; System call 'write'
        mov     ebx,1             ; 'stdout'
        mov     ecx,msg           ; Address of message
        mov     edx,msg_size      ; Length  of message
        int     0x80              ; All system calls are done via this interrupt

        mov     eax,1             ; System call 'exit'
        xor     ebx,ebx           ; Exitcode: 0 ('xor ebx,ebx' saves time; 'mov ebx, 0' would be slower)
        int     0x80

;================== data =====================
segment readable writeable
;=============================================

msg db 'Hello world!',0xA
msg_size = $-msg

As you may have noticed, writing a simple Hello World program in FASM isn’t hard at all.

:

2 Comments for this entry

  • ezequiel

    Hello i will use this article in my website. I will refer you. Jejejeje, i am trying to learn assembler, and your example is preaty good. Thanks u

    mov eax,1
    xor ebx,ebx
    int 0x80 ;BYE!

  • admin

    Thanks for your comment as well as for referring me. You just got a backlink as I approved your comment. I hope you’ll find the code useful.

Leave a Reply

*

Looking for something?

Use the form below to search the site:

Still not finding what you're looking for? Drop a comment on a post or contact us so we can take care of it!