flat assembler
Message board for the users of flat assembler.

Index > Windows > Windows Console Programming?

Author
Thread Post new topic Reply to topic
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Hey... I was wondering how would I write a console "Hello World!" app in FASM?
Post 26 Jan 2009, 02:52
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
Code:
format pe console
include 'win32ax.inc'

.data

_message db 'Hello World!',13,10
_message.len       = $ - _message

.code

begin:
        push    eax
        invoke  GetStdHandle,STD_OUTPUT_HANDLE
        mov     ecx,esp
        invoke  WriteFile,eax,_message,_message.len,ecx,0
        pop     eax
        invoke  ExitProcess,0

.end begin    
Post 26 Jan 2009, 03:07
View user's profile Send private message Visit poster's website Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:53; edited 1 time in total
Post 26 Jan 2009, 03:20
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Thanks, but I mean is there a way to call PrintF in FASM?

Also, rather than using "invoke" is it possible to use "call" for OS functions?

Thanks!
Post 27 Jan 2009, 04:12
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
rhyno_dagreat wrote:
Thanks, but I mean is there a way to call PrintF in FASM?
You can call wsprintf to print to a memory buffer. But you still need to get it to the screen with something like WriteFile (or do you want to access the C library?). Try not to be swayed by the name of the function. A rose by any other name ...
rhyno_dagreat wrote:
Also, rather than using "invoke" is it possible to use "call" for OS functions?!
With one exception all Win32 API function are stdcall compliant. If you don't use invoke then you will manually need to push the parameters onto the stack before calling.
Post 27 Jan 2009, 04:32
View user's profile Send private message Visit poster's website Reply with quote
asmcoder



Joined: 02 Jun 2008
Posts: 784
asmcoder
[content deleted]


Last edited by asmcoder on 14 Aug 2009, 14:53; edited 1 time in total
Post 27 Jan 2009, 05:02
View user's profile Send private message Reply with quote
Picnic



Joined: 05 May 2007
Posts: 1288
Location: behind the arc
Picnic
rhyno_dagreat wrote:

Also, rather than using "invoke" is it possible to use "call" for OS functions


Hi rhyno_dagreat,
If you don't like invoke -the way it sounds- you can use fix to replace it with something else. Smile
Code:
        format pe console

        include 'win32ax.inc'                      ; + CRTDLL.DLL

        api fix invoke
        print fix cinvoke printf,

.data
    text db 'Hello World!',0

.code
main:
        print text
        api ExitProcess, 0

.end main
    
Post 27 Jan 2009, 16:45
View user's profile Send private message Reply with quote
rhyno_dagreat



Joined: 31 Jul 2006
Posts: 487
Location: Maryland, Unol Daleithiau
rhyno_dagreat
Thank you all for the help!

When I'm pushing params on the stack, do I push them in the order they go in, or reverse order?

Also I was hoping to be able to use the C-library.

Truth be told, I'm very new to Windows programming in ASM, so I don't know where to begin with it or what is needed to write a program - especially when it comes to console programming (which is something I would like to know how to do first). But I do know that I like using classic-style ASM routines which means call instead of invoke and such.

Thanks!
Post 27 Jan 2009, 21:01
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
I have an example using MSVCRT.DLL, but it's 64-bit:
http://board.flatassembler.net/topic.php?p=86947#86947

...32-bit would be pushing the arguments in reverse order, and correcting the stack, iirc.
Post 28 Jan 2009, 02:58
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1160
Azu
revolution wrote:
With one exception all Win32 API function are stdcall compliant
What is the exception?


I thought stdcall was the same as invoke except it doesn't put the [] automatically.. :s
Post 17 Feb 2009, 11:38
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
Unlike other Windows functions, wsprintf uses the C calling convention (_cdecl), rather than the Pascal calling convention. As a result, it is the responsibility of the calling process to pop arguments off the stack, and arguments are pushed on the stack from right to left. In C-language modules, the C compiler performs this task.
Post 17 Feb 2009, 11:46
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1160
Azu
Interesting, thanks!

I think the C calling convention would make more bloated code then.
Post 17 Feb 2009, 11:58
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 2915
Location: [RSP+8*5]
bitRAKE
Not necessarily, the parameter stack space broadens the interface between caller and callee beyond the single return value. A more cohesive design can reuse this space in very productive ways - stack correction being used rarely.
Post 17 Feb 2009, 17:08
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17279
Location: In your JS exploiting you and your system
revolution
bitRAKE wrote:
Not necessarily, the parameter stack space broadens the interface between caller and callee beyond the single return value. A more cohesive design can reuse this space in very productive ways - stack correction being used rarely.
It is a possibility to do that, but I have never seen it done. The Windows 64bit calling standard is closer to achieving this.

And Azu is correct, many a C program is bloated these days. But that has nothing to do with the calling standard Wink
Post 17 Feb 2009, 18:45
View user's profile Send private message Visit poster's website Reply with quote
Yardman



Joined: 12 Apr 2005
Posts: 245
Location: US
Yardman
[ Post removed by author. ]


Last edited by Yardman on 04 Apr 2012, 03:27; edited 1 time in total
Post 18 Feb 2009, 00:08
View user's profile Send private message Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1160
Azu
bitRAKE wrote:
Not necessarily, the parameter stack space broadens the interface between caller and callee beyond the single return value. A more cohesive design can reuse this space in very productive ways - stack correction being used rarely.
Oh. I thought he meant it was the same as stdcall except you have to put the pop instructions in your code every time you make a call, instead of them just being in the function, which would be retarded and bloat code size for no good reason.
Post 18 Feb 2009, 00:53
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.