flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > how i can return value from macro? something like EXITM.

Author
Thread Post new topic Reply to topic
dead_body



Joined: 21 Sep 2005
Posts: 187
Location: Ukraine,Kharkov
dead_body
subj. can i do it in fasm now, or it will be in future? Question

//sorry for bad english Embarassed
Post 21 Sep 2005, 08:22
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
Code:
macro some_macro return_variable,[parameters] {
return_variable = something
}

some_macro the_value,1,2,3,4
mov eax,the_value    
Post 21 Sep 2005, 08:56
View user's profile Send private message Visit poster's website Reply with quote
dead_body



Joined: 21 Sep 2005
Posts: 187
Location: Ukraine,Kharkov
dead_body
oh,sorry. now i'll try to explain what i want using an example.

I have:
Code:
macro strlen    arg,arg2        {       push arg
                                                Call GetStringLength ;simple proc
                                                if arg2 eq
                                                                        
                                                else
                                                        add eax,arg2
                                                end if
                                        }
    



and i use it like this:
Code:
strlen edi
    

and i need:
Code:
mov ecx,strlen edi    


how can i do this? if can Sad
Post 21 Sep 2005, 09:17
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17716
Location: In your JS exploiting you and your system
revolution
Code:
macro strlen soure,op {
push source
Call GetStringLength ;simple proc
op,eax
}
strlen edi,add ebx
strlen edi,mov ecx
    
Post 21 Sep 2005, 09:30
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
tis isn't possible in FASM. anyway "macro" means "macroinstruction", purpose of "macro" is to emulate instruction. what you want is called inline macro, i suggest creating macro for declaring string, which also creates constant with string size, like
Code:
struc string [value]
{common
  local ..here
  ..here:
  . db value
  siozeof#. = $ - ..here
}
my_string string 'aaaaaaaa'
mov ecx,sizeof.my_string
    

or you can even overload "db" itself:
Code:
struc db [value]
{common
  local ..here
  ..here:
  . db value
  siozeof#. = $ - ..here
}
my_string db 'aaaaaaaa',0
my_data db 10,50,'abc',0
mov ecx,sizeof.my_string
mov eax,sizeof.my_data
    

this creates sizeof.<name> for everything defined with "db".

For non-constant string, i would suggest this:
Code:
macro strlen where,what
{
  if !(where eq eax)
     push eax
  end if
  invoke GetStringLength,what
  if !(where eq eax)
    mov where,eax
    pop eax
  end if
}
strlen eax,my_string ;puts length of "my_string" to eax
    


Last edited by vid on 21 Sep 2005, 10:54; edited 2 times in total
Post 21 Sep 2005, 10:47
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
dead_body



Joined: 21 Sep 2005
Posts: 187
Location: Ukraine,Kharkov
dead_body
Code:
 
strlen edi,add ebx 
strlen edi,mov ecx
    

but it looks not very readeble.
Maybe in future,when fasm preprocessor will be more powerfull,
(exitm <eax>) will be created, am I right Tomasz Grysztar? Question


revolution
great thanks to you. You variant is better,yet. Wink
Post 21 Sep 2005, 10:47
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
dead_body: seems we replied at the same time, don't miss my reply Wink

IMHO there's no reason to use macro for purpose, 2 extra lines are not problem, and it is more readable than looking for what your macro does etc.
Post 21 Sep 2005, 10:55
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7802
Location: Kraków, Poland
Tomasz Grysztar
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.

Look at the macros in extended Win32 header (especially the "pushd") to see how this principle affects the solutions.
Post 21 Sep 2005, 10: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.