Hi RagingGrim,
Good to see you here! I saw your question at SO the other day, and was going to suggest that we might have some examples in the "Examples" section (duh!). Turns out that we don't have a simple console example. We should!
I haven't touched Windows since Win98, but digging through the dusty archives I came up with this. As I recall, it "worked", but it is not correct!
; nasm -f win32 hw32cons.asm
; link /entry:start /subsystem:console hw32cons.obj <wherever>\kernel32.lib
%define ExitProcess _ExitProcess@4
%define WriteFile _WriteFile@20
global _start
extern ExitProcess
extern WriteFile
section .text
_start:
push dword 0
push dword num_chars
push dword MSGLEN
push dword msg
push dword -11
call WriteFile
exit_ok: push dword 0
exit: call ExitProcess
section .data
num_chars dd 0
msg db 'Hello, Console.', 13, 10
MSGLEN equ $ - msg
I think the correct way to do it is:
; nasm -f win32 hw32cons.asm
; link /entry:start /subsystem:console hw32cons.obj <wherever>\kernel32.lib
%define ExitProcess _ExitProcess@4
%define GetStdHandle _GetStdHandle@4
%define WriteFile _WriteFile@20
global _start
extern ExitProcess
extern GetStdHandle
extern WriteFile
section .text
_start:
push -11 ; defined as "STDIN" somewhere, no doubt
call GetStdHandle
; should return our handle in eax
push dword 0
push dword num_chars
push dword MSGLEN
push dword msg
push eax
call WriteFile
exit_ok: push dword 0
exit: call ExitProcess
section .data
num_chars dd 0
msg db 'Hello, Console.', 13, 10
MSGLEN equ $ - msg
That's untested, but I think it "should work".
I am unable to advise what the command line to ld should be. I think I got it to work (using Cygwin, not MinGW) by pointing it to a library I got from Hutch's "MASM32" package once...
The NASMX package -
http://nasmx.sf.net - contains some macros and a lot of "%defines" and examples, but I don't think it has any actual libraries. It uses Golink rather than ld, and in that case we can just list the .dlls we need on the command line. Perhaps MinGW includes the libraries you need? (Might need to use the uppercase "-L/path/to/library" switch as well as the "-l thelib" switch?)
I apologize for not having a better answer for you. I'm pretty stubborn about "I don't use Windows anymore" (not even Wine). Maybe someone can provide a "known to work" example. Seems like a simple enough request...
Best,
Frank
Well, I see Ralph has posted a "better" example. Good luck!