flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Temporary Labels

Author
Thread Post new topic Reply to topic
Pinecone_



Joined: 28 Apr 2008
Posts: 180
Pinecone_ 20 Nov 2008, 14:53
I've been trying to write my own Proc macros, just for the learning experience.
I'm just going to ignore local stuff for now to avoid complication...
The only problem i've had is defining the argument names at their correct location (Ebp+8+...)
The label directive can define it fine as follows:
Code:
Label Args Dword AT Ebp + 4 + (ArgCount * 4)    
however the manual says
Quote:
Each label can be defined only once.
therefore i can't have the same name for arguments in diferent procs... i tried to get around this by restoring it with
Code:
Args EQU    
however this resulted in an invalid expression when i used the label.. I thought it was strange that it did not produce an error saying symbol already defined...






Anyway, next I tried defining it like...
Code:
Args EQU Ebp + 4 + (ArgCount * 4)     
and restoring with...
Code:
Args EQU    
which works, but i need to specify the size every time i want to use it... eg:
Code:
mov eax, dword [argument]    
which is not ideal.


So my question: How can i make "Temporary Labels" only avaliable in the proc (restore with the EndP macro) that are size-aware.. so i dont have to specify dword every time i want to use them...? Thanks in advance


Here's the full macro i'm using just to clarify any other questions... (no-one else i've seen seems to write macros like i do.. Razz it's strange)
Code:
Macro Proc Name, [Args] {
     Common
              
            Label Name
          Push Ebp
            Mov Ebp, Esp
                
            Local ArgCount
              ArgCount = 0
                
    Forward
             IF ~ Args EQ
                        ArgCount = ArgCount + 1
                     Label Args Dword AT Ebp + 4 + (ArgCount * 4)
                        ; Args EQU Ebp + 4 + (ArgCount * 4) 
                End IF
      Common
              
            Macro Ret \{
                  Leave
                       Ret ArgCount * 4
            \}
            
            Macro EndP \{
                 
                    Forward
                             
                            IF ~ Args EQ
                                        Args EQU
                            End IF
                      
                    Common 
                             
                            Purge Ret
                           Purge EndP
                          
            \}
            
}    


Last edited by Pinecone_ on 20 Nov 2008, 15:26; edited 1 time in total
Post 20 Nov 2008, 14:53
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20433
Location: In your JS exploiting you and your system
revolution 20 Nov 2008, 14:59
Pinecone_ wrote:
How can i make "Temporary Labels" only avaliable in the proc
Use local, that is what it is for.
Post 20 Nov 2008, 14:59
View user's profile Send private message Visit poster's website Reply with quote
Pinecone_



Joined: 28 Apr 2008
Posts: 180
Pinecone_ 20 Nov 2008, 15:08
Is local not only for the macro language? Whatever i define in local would not be avaliable for use in between the Proc and EndP if my understanding of them is correct... I don't quite see how that would work.

I wish to use the above macro like...
Code:
Proc Test, Arg1, Arg2, Arg3
       Mov Eax, [Arg1]
Ret
EndP    
and have it compiled to...
Code:
Push Ebp
Mov Ebp, Esp
     Mov Eax, [Ebp + 0x08]
Leave
Ret 0x0C    
Post 20 Nov 2008, 15:08
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20433
Location: In your JS exploiting you and your system
revolution 20 Nov 2008, 15:20
Have a look at the fasm proc macro in the download to see how it is easily done.

Since proc is a macro you can use local to define labels and then use an equ to map it to the desired programmer selected name.
Code:
local someLabel ;internally defined as someLabel?blahblah
label somelabel ...
MyLabel equ someLabel
mov eax,[MyLabel]    
Post 20 Nov 2008, 15:20
View user's profile Send private message Visit poster's website Reply with quote
Pinecone_



Joined: 28 Apr 2008
Posts: 180
Pinecone_ 20 Nov 2008, 15:30
That makes complete sense, and yet i still managed to fail Razz After trying what you said, i'm getting error "undefined symbol 'SomeLabel?QT'."
using this...
Code:
Local SomeLabel
IF ~ Args EQ
   ArgCount = ArgCount + 1
     Label SomeLabel Dword AT Ebp + 4 + (ArgCount * 4)
   Args EQU SomeLabel
End IF
    
Post 20 Nov 2008, 15:30
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20433
Location: In your JS exploiting you and your system
revolution 20 Nov 2008, 16:31
Remember that if and equ are processed at different stages. However since you have not posted the entire macro and it's instantiation code we cannot help you to fix it.
Post 20 Nov 2008, 16:31
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 20 Nov 2008, 19:09
Pinecone_,

You may look at proc macro from STDCALL.INC in earlier versions of fasm. For example, 1.51:
Code:
macro proc name,[arg]                    ; define procedure
 { common
    name:
    virtual at ebp+8
    if ~ arg eq
   forward
     local ..arg
     ..arg dd ?
     arg equ ..arg
   common
     end if
     ..ret = $ - (ebp+8)
    end virtual
    local ..dynamic_data,..dynamic_size
    dynamic_data equ ..dynamic_data
    dynamic_size equ ..dynamic_size
    virtual at ebp - dynamic_size
     dynamic_data: }    
Post 20 Nov 2008, 19:09
View user's profile Send private message Reply with quote
Pinecone_



Joined: 28 Apr 2008
Posts: 180
Pinecone_ 21 Nov 2008, 00:55
Thank you revolution and baldr. And revolution, i forgot to mention that i edited the first post and gave the whole macro after you posted. Here's the macro now working. (Thank you!)
Code:
Macro Proc Name, [Args] {
 Common
              
            Label Name
          Push Ebp
            Mov Ebp, Esp
                
            Local ArgCount
              ArgCount = 0
                
            IF ~ Args EQ
                Virtual AT Ebp + 8
  Forward
             ArgCount = ArgCount + 1
             Local ..Arg
         ..Arg DD ?
          Args EQU ..Arg
      Common
              End Virtual
         End IF
              
            Macro Ret \{
                  Leave
                       Ret ArgCount * 4
            \}
            
            Macro EndP \{
                 
                    Forward
                             
                            IF ~ Args EQ
                                        Args EQU
                            End IF
                      
                    Common 
                             
                            Purge Ret
                           Purge EndP
                          
            \}
            
}    
Post 21 Nov 2008, 00:55
View user's profile Send private message 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.