beta.blog

Programming

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 : more...

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!