DaniWeb IT Discussion Community

Code Snippets (http://www.daniweb.com/code/)
-   fasm (http://www.daniweb.com/code/fasm.html)
-   -   Hello, world! in FASM (http://www.daniweb.com/code/snippet486.html)

Narue fasm syntax
Apr 26th, 2006
Some languages are hard to get started in. FASM appears to be one of these languages because the documentation is not detailed enough for a beginner. That's a shame because FASM is (in my opinion) one of the better assemblers. The following snippet is a simple Hello, world! program which FASM will directly output an executable on Windows.

The C run-time library is used by accessing the msvcrt DLL, so a linker isn't necessary.

  1. format PE console
  2. entry start
  3.  
  4. include 'C:\fasm\include\win32a.inc'
  5.  
  6. ;======================================
  7. section '.data' data readable writeable
  8. ;======================================
  9.  
  10. hello_msg db 'Hello, world!',0
  11.  
  12. ;=======================================
  13. section '.code' code readable executable
  14. ;=======================================
  15.  
  16. start:
  17. ccall [printf],hello_msg
  18. ccall [getchar]
  19. stdcall [ExitProcess],0
  20.  
  21. ;====================================
  22. section '.idata' import data readable
  23. ;====================================
  24.  
  25. library kernel,'kernel32.dll',\
  26. msvcrt,'msvcrt.dll'
  27.  
  28. import kernel,\
  29. ExitProcess,'ExitProcess'
  30.  
  31. import msvcrt,\
  32. printf,'printf',\
  33. getchar,'_fgetchar'