flat assembler
Message board for the users of flat assembler.

Index > Main > How to write subroutine and call subroutine?

Author
Thread Post new topic Reply to topic
whileloop



Joined: 15 Feb 2009
Posts: 3
whileloop 15 Feb 2009, 23:07
I readed the doc & example pages, and also the fasm.pdf. The doc mentioned invoke, stdcall, cinvoke, ccall, proc, endp. But I don't know how to balance the stack.

In masm I just define a subroutine and invoke it. The masm/macro balance the stack automatically.

In fasm I define a subroutine and stdcall it. The program crash. Do I have to manage ESP, EBP and RET <int> in my subroutine? I looked at the examples, their procedure just use RET, and don't need to take care ESP, EBP.

I am very confused. Can someone give a simple example to show me how to do it correctly, please?
Post 15 Feb 2009, 23:07
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 15 Feb 2009, 23:14
Have you spelled RET as "ret" (i.e. all lowercase)? It is important because the proc macro defines the ret macro but not RET nor any other combination of lower and upper case.
Post 15 Feb 2009, 23:14
View user's profile Send private message Reply with quote
whileloop



Joined: 15 Feb 2009
Posts: 3
whileloop 15 Feb 2009, 23:24
Oh! I didn't know that ret is macro, while RET is mnemonic.
Problem solved.
Thank you very much!!
Post 15 Feb 2009, 23:24
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 15 Feb 2009, 23:45
It is a macro under the proc context, otherwise it is also a mnemonic of the CPU instruction RET (endp macro purges ret macro). There is no case sensitivity for CPU instructions but macros are case sensitive.

Code:
macro endp
 { purge ret,locals,endl
   finish@proc
   purge finish@proc
   restore regs@proc
   match all,args@proc \{ restore all \}
   restore args@proc
   match all,all@vars \{ restore all \} }    
Post 15 Feb 2009, 23:45
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 15 Feb 2009, 23:48
By default, "ret" in any combination of lowcase/upcase case letters is mnemonic too, it is just aliast for "retn". But inside "proc", this instruction is overloaded by "ret" macro. Problem is, macro names in FASM are case sensitive, so only "ret" gets overloaded, and "RET", "Ret", "ReT" etc. all remain just aliases for "retn".
Post 15 Feb 2009, 23:48
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.