flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > macro: howto get function parameters as offset from ebp

Author
Thread Post new topic Reply to topic
wisepenguin



Joined: 30 Mar 2005
Posts: 129
wisepenguin
ive been trying to make a simple macro to help in making a function.
all it does is set up a label, and parameters.

first i tried setting up the parameters as equates to ebp+OFFSET but that wasnt working, and kept on being ebp+8 for every argument.

so now i tried this, and gives the same.
im trying to use %, from the manual to get the current time through repeating, and use (% * 4) + 4, to give the offset.

here is the simplest form of what i have and i cant make it work.
any help would be appreciated.

Code:
; ----- ----- ----- -----
; .function
; declares a function, and parameters is has
; ----- ----- ----- -----
macro .function funcname, [args]
{       
        forward
                virtual at ebp+%*4+4
                        args dd ?
                end virtual
; args equ ebp+%*4+4  ; tried this aswell
        common
                funcname:

                push ebp
                mov ebp, esp

                push ebx
                push edi
                push esi
                
}
    
Post 23 Jan 2006, 07:44
View user's profile Send private message Reply with quote
wisepenguin



Joined: 30 Mar 2005
Posts: 129
wisepenguin
my mistake, i cant use % because there is no repeat.

does anyone know how to achieve what im trying to do without % ?
Post 23 Jan 2006, 07:53
View user's profile Send private message Reply with quote
chris



Joined: 05 Jan 2006
Posts: 62
Location: China->US->China->?
chris
I think all you need is a variable inside this macro which increases with the number of arguments. You can define this variable in the 'common'
block, and inc it in the forward block. Like this one:
Code:
macro test [arg]
{
        common
                argn = 0
        forward
                display `arg
                display argn + '0',' '
                argn = argn + 1
}

test arg,arg,arg
    
Post 24 Jan 2006, 03:22
View user's profile Send private message Reply with quote
wisepenguin



Joined: 30 Mar 2005
Posts: 129
wisepenguin
thanks chris.
i tried your way and it worked. the several ways i tried were obviously wrong Smile

here is the code that works, and sample usage

Code:
; ----- ----- ----- -----
; .function
; declares a function, and parameters is has
; ----- ----- ----- -----
macro .function funcname, [args]
{               
        common
                count = 8
                funcname:

                push ebp
                mov ebp, esp

                push ebx
                push edi
                push esi
                
        forward
                virtual at ebp+count
                        args dd ?
                end virtual
                count = count + 4
}

; sample usage
.function my_func, param1, second_param

cmp [param1], 12
je .SOME_LABEL

; rest of function etc. ..
; restore stack etc....
    


thanks again
Post 24 Jan 2006, 03:44
View user's profile Send private message Reply with quote
chris



Joined: 05 Jan 2006
Posts: 62
Location: China->US->China->?
chris
well, I think Tomasz has defined a macro 'proc' with this purpose and as well as a set of fully featured procedure macros(in PROC32.INC). You can look it up in the fasm manual if you don't want to do everything from scratch. And actually the count/argn is better preceeded with 'local', sorry for that. I just switched to fasm a couple of weeks ago, so mistakes are expected Wink
Post 24 Jan 2006, 04:43
View user's profile Send private message Reply with quote
wisepenguin



Joined: 30 Mar 2005
Posts: 129
wisepenguin
oh i know about the macros provided, they are good!
i was just doing this as an exercise to try and improve my macro skills.

i like fasm Smile one reason is i like that varname is always address, and [varname] is value because i started with masm and sometimes got a bit confused by putting OFFSET and ADDR before names.
Post 24 Jan 2006, 07:27
View user's profile Send private message Reply with quote
Borsuc



Joined: 29 Dec 2005
Posts: 2466
Location: Bucharest, Romania
Borsuc
wisepenguin wrote:
i like fasm Smile one reason is i like that varname is always address, and [varname] is value because i started with masm and sometimes got a bit confused by putting OFFSET and ADDR before names.


I like Fasm because of it's powerful macro preprocessor and assembler, and also because of it's clear syntax (like you said). Wink
Post 25 Jan 2006, 19:01
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-2020, Tomasz Grysztar.

Powered by rwasa.