beta.blog

FASM: Hello World (Windows/Console)

by on Oct.13, 2011, under Programming

This example code demonstrates how to write a simple Windows (console) Hello World application in flat assembler. The example code uses the C library in order to print text.

format PE console
entry start

include 'win32a.inc'

;======================================
section '.data' data readable writeable
;======================================

hello_newline    db "Hello World!",10,0
hello_no_newline db "Hello World! (without a new line)",0

;=======================================
section '.code' code readable executable
;=======================================

start:

        ccall   [printf],hello_newline      ; Print 'Hello World!' and start a new line.
        ccall   [printf],hello_no_newline   ; Print 'Hello World!' without starting a new line.

        ccall   [getchar]                   ; I added this line to exit the application AFTER the user pressed any key.
        stdcall [ExitProcess],0             ; Exit the application

;====================================
section '.idata' import data readable
;====================================

library kernel,'kernel32.dll',\
        msvcrt,'msvcrt.dll'

import  kernel,\
        ExitProcess,'ExitProcess'

import  msvcrt,\
        printf,'printf',\
        getchar,'_fgetchar'
:

1 Comment for this entry

  • Sheen

    Hi! may I ask how can i add two hexadecimals in FASM and their result should be displayed in command prompt. Thank you

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!