DaniWeb IT Discussion Community

Code Snippets (http://www.daniweb.com/code/)
-   fasm (http://www.daniweb.com/code/fasm.html)
-   -   Variations on Hello, world! (http://www.daniweb.com/code/snippet487.html)

Narue fasm syntax
Apr 26th, 2006
FASM can output an executable PE directly, but sometimes you want to output an object file for linking with modules in other languages. The following program can be used to link with the C library of the GCC compiler with the following commands:

C:\>fasm hello.asm hello.obj
C:\>gcc hello.obj -o hello.exe

It's almost like magic!

  1. format MS COFF
  2.  
  3. include 'C:\fasm\include\win32a.inc'
  4.  
  5. ;======================================
  6. section '.data' data readable writeable
  7. ;======================================
  8.  
  9. hello_msg db 'Hello, world!',0
  10.  
  11. ;=======================================
  12. section '.text' code readable executable
  13. ;=======================================
  14.  
  15. public _main
  16. extrn '_printf' as printf
  17.  
  18.  
  19. _main:
  20. ccall printf,hello_msg
  21. xor eax,eax
  22. ret