In result to my post Can I use int21h on windows xp to print things?, I have seen an article about using Windows API's and in this article was a reference to using the _WriteConsole@4 API to print a message to the console. The article is at http://cs.lmu.edu/~ray/notes/x86assembly/.
Here is my code so far:
.386P
.model flat
extern _ExitProcess@4:near
extern _GetStdHandle@4:near
extern _WriteConsoleA@20:near
public _go
.data
msg byte 'if you get this, it worked.', 10
handle dword ?
written dword ?
.code
start:
_go:
push -11
call _GetStdHandle@4
mov handle, eax
push 0
push offset written
push 13
push offset msg
push handle
call _WriteConsoleA@20
push 0
call _ExitProcess@4
end start
I am using this syntax to compile the code: ML:
ml (the file is called test.asm) test.asm /c
Link:
link test.obj C:\masm32\lib\kernel32.lib /SUBSYSTEM:CONSOLE /entry:go
I have gotten it to compile and link, but when I run the .exe that is produced, it does absolutely nothing, not even an error return. The console is just black. Why is this?
Any help would be greatly appreciated. And to the users of this forum, I apologize for bombarding stackoverflow.com every day, it is just that I have very few resources to learn with.
Thanks in advance,
Progrmr
This works without problem:
include masm32rt.inc
.data
szMsg db "I am in the console!", 0
MSG_LEN equ $ - szMsg
.data?
BytesWriten dd ?
.code
start:
push STD_OUTPUT_HANDLE
call GetStdHandle
push NULL
push offset BytesWriten
push MSG_LEN
push offset szMsg
push eax
call WriteConsole
push 0
call ExitProcess
end start
your entry label is _go yet you tell the linker is is go - /entry:go so it creates the console but does not execute any code! You don't need to tell the linker the entry point in this case, your entry point is start... How does the linker know? The end start
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With