flat assembler
Message board for the users of flat assembler.

Index > Main > return value for macro

Author
Thread Post new topic Reply to topic
khanh1984



Joined: 13 Jul 2009
Posts: 17
khanh1984
anyone thinks we should implement the macro in a way that allows ruturn value like a fuction.

A very simple example is an implementation of macro sizeof.

For every structure that are not yet defined sizeof structure inside I want to implement something looks like:

Code:
macro sizeof structure
{
virtual at 0
xyz structure
@:
abc = @-0 ;sizeof value here
return sizeof  ; now sizeof structure = size of that structure if structure is valid
}

    

of course there will be another way around but my example is the simplest solution and you can find many cases where you can use this feature.
Post 17 Jul 2009, 02:31
View user's profile Send private message Reply with quote
khanh1984



Joined: 13 Jul 2009
Posts: 17
khanh1984
Dear Tomasz,

I've think of very simple idea to implement this feature. in macro we will add another type such as:

word macro sizeof Structure
{
macro inside here
return value
}
So when fasm encounters the macro above, it realizes that this macro is different from normal macro 'cause it has type 'word' in front. Then it decides to implement a normal macro of random name with same code inside, it will calculate all the value based on that macro. Finally, after have return value, it simplies define a constant with the name sizeof structure to that value.

What do you think about my idea. Please post your opinion.
Post 17 Jul 2009, 08:22
View user's profile Send private message Reply with quote
Fanael



Joined: 03 Jul 2009
Posts: 168
Fanael
Tomasz, please don't implement inline macros in FASM!
Post 17 Jul 2009, 08:33
View user's profile Send private message Reply with quote
khanh1984



Joined: 13 Jul 2009
Posts: 17
khanh1984
Fanael,
What do mean by inline macro ???
I only know inline asm in high-level language
and why do you think it is bad??? please give your answer in more detail?
Post 17 Jul 2009, 09:39
View user's profile Send private message Reply with quote
Fanael



Joined: 03 Jul 2009
Posts: 168
Fanael
Tomasz Grysztar wrote:
No, inlining the macros is something against the fasm's concept. The macro in fasm is just a special kind of "mnemonic", which gets converted into chain of other lines by preprocessor. Just like each assembly language instruction spans one line, the macroinstruction spans one line.
http://board.flatassembler.net/topic.php?p=30436#30436
Post 17 Jul 2009, 12:35
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3045
Location: vpcmipstrm
bitRAKE
Here are a couple way to implement return values:
Code:
macro sizeof structure {
        local ..xyz
 virtual at 0
                ..xyz structure
             sizeof.return = $ - ..xyz
   end virtual
}

macro sizeof return,structure {
   local ..xyz
 virtual at 0
                ..xyz structure
             return = $ - ..xyz
  end virtual
}    
edit: thanks, LocoDelAssembly


Last edited by bitRAKE on 18 Jul 2009, 23:47; edited 2 times in total
Post 17 Jul 2009, 13:43
View user's profile Send private message Visit poster's website Reply with quote
Azu



Joined: 16 Dec 2008
Posts: 1159
Azu
Here you go

macro return value{
mov eax,value
ret
}


Last edited by Azu on 18 Jul 2009, 18:15; edited 1 time in total
Post 18 Jul 2009, 03:49
View user's profile Send private message Send e-mail AIM Address Yahoo Messenger MSN Messenger ICQ Number Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
@Azu: shouldn't you reverse the name & parameter? Razz
Post 18 Jul 2009, 18:01
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4633
Location: Argentina
LocoDelAssembly
bitRAKE's code needs a little adjustment, it is better to use "local ..xyz" to not interfere with the caller scope.
Post 18 Jul 2009, 18:27
View user's profile Send private message Reply with quote
khanh1984



Joined: 13 Jul 2009
Posts: 17
khanh1984
bitRake:

I understand your macro but for the command like this:

mov eax, sizeof structure

how your macro fits in this situation. I mean when fasm encounters the line above, it will replace sizeof structure with your macro but the above like is one line command, your macro is 2 line so how you will be sure that Fasm will replace only sizeof.return value in that "mov" instruction.
Post 23 Jul 2009, 06:44
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3045
Location: vpcmipstrm
bitRAKE
FASM doesn't support inline macros, and I'm not attempting to solve inline (one line) macro problem. Use two lines in source code. Example, http://board.flatassembler.net/topic.php?t=10472
Post 23 Jul 2009, 13:56
View user's profile Send private message Visit poster's website 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. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.