tags:

views:

247

answers:

3

The code I currently have can be found at: http://fasm.pastebin.com/yY3C0aVF I'm exceptionally new to assembly, only picked it up yesterday and I've looked through many an example and still can't figure out for myself how to write to the console. I always get an error when I seem to replicate it in my own way. If I'm not on the right track at all please let me know, also if you can suggest a good book on fasm it would be greatly appreciated.

A: 

It seems you're essentially trying to write a hello world program. Have a look at the answers to this question and compare with your code. This should get you further.

PhiS
+1  A: 

The easiest way is to use the C functions. In its simplest use, printf() takes a string as a parameter and writes it on the standard output.

This code should work:

format PE console
entry start

include 'win32a.inc'

section '.text' code executable
start:
        push hello
        call [printf]
        pop ecx

        push 0
        call [ExitProcess]

section '.rdata' data readable
        hello db 'Hello world!', 10, 0

section '.idata' data readable import
        library kernel32, 'kernel32.dll', \
                msvcrt,   'msvcrt.dll'
        import kernel32, ExitProcess, 'ExitProcess'
        import msvcrt, printf, 'printf'
Bastien Léonard
+1  A: 

Use WriteConsole.

include 'win32wxp.inc'

.code
  start:
        invoke  AllocConsole
        invoke  WriteConsole,<invoke GetStdHandle,STD_OUTPUT_HANDLE>,tex,12,dummy,0
        invoke  Sleep,-1
.end start

.data
tex     TCHAR   'Hello World!'
dummy   rd      1  
Jens Björnhager