flat assembler
Message board for the users of flat assembler.

Index > Windows > calling api functions

Author
Thread Post new topic Reply to topic
MSBob



Joined: 17 Jun 2004
Posts: 2
MSBob
Hi

I'm pretty new to assembly and decided to use Flat Assembler to learn with.

I'm having a bit of difficulty understanding how api functions are actually called, as all the examples I can find simply use the invoke macro. As I'm trying to learn how things are done without macros I want to do it manually.

My understanding was that the arguments are pushed on to the stack in reverse order, and then the api function is called. When I do this however, the program just crashes. Using invoke and it works fine.

Could someone please explain where I'm going wrong? Here is the test code.

Code:
format PE GUI 4.0
include "%fasminc%\win32a.inc"

section ".data" data readable writeable

Caption db "Hello!",0
Text db "Hello assembly world!",0

section ".code" code readable executable
entry start
start:

push MB_OK or MB_ICONEXCLAMATION
push Caption
push Text
push NULL
call MessageBox
;invoke MessageBox,NULL,Text,Caption,MB_OK or MB_ICONEXCLAMATION

push NULL
call ExitProcess
;invoke ExitProcess,NULL

section ".import" import data readable writeable

library kernel,"KERNEL32.DLL",\
        user,"USER32.DLL"

import kernel,\
       ExitProcess,"ExitProcess"

import user,\
       MessageBox,"MessageBoxA"

    
Post 17 Jun 2004, 15:27
View user's profile Send private message Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7713
Location: Kraków, Poland
Tomasz Grysztar
The labels for API calls are actually labels to pointers to the functions, not to the functions themselves. Therefore you have to call them this way:
Code:
push MB_OK or MB_ICONEXCLAMATION 
push Caption 
push Text 
push NULL 
call [MessageBox] 
;invoke MessageBox,NULL,Text,Caption,MB_OK or MB_ICONEXCLAMATION 

push NULL 
call [ExitProcess]
;invoke ExitProcess,NULL     

Note use of the square brackets inside the invoke macro.
Post 17 Jun 2004, 15:41
View user's profile Send private message Visit poster's website Reply with quote
MSBob



Joined: 17 Jun 2004
Posts: 2
MSBob
Privalov wrote:
The labels for API calls are actually labels to pointers to the functions, not to the functions themselves. Therefore you have to call them this way:


Thanks for the explanation, it works now. I obviously still have a lot to learn Smile
Post 17 Jun 2004, 18:26
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
i am sure i explained this question (+somewhat more) very deeply in some post, but forgot in which, maybe you could browse forum and find it
Post 17 Jun 2004, 19:47
View user's profile Send private message Visit poster's website AIM Address 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.