flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > How to define a table of function pointers using macros? |
Author |
|
JohnFound 26 Dec 2004, 08:12
Of course it is possible, with only limitation that the pointer table must stay after the last function.
The main idea is to have one globa symbolic costant and on every "functions" to add the function name to the constant: Code:
FunctionList equ FunctionList, functionName
At the end you will have FunctionList containing all functions names separated with commas. Then you have to define second macro "BuildFunctionTable" and to pass to it this list: Code: macro BuildFunctionsTable [func] { forward dd func } This is very simplified description. You can look at "globals.inc" macroses from the project Fresh - they use similar technique to make global data definitions. Regards. |
|||
26 Dec 2004, 08:12 |
|
ronware 27 Mar 2005, 23:00
Hi, JohnFound -
Since you posted that response, I had gone to using Perl to extract the information the way I want. But now I am revisiting the problem, and I am getting more questions than answers The attached file 'test.asm' illustrates what I am trying to do, and the problem I am having. Basically, I have a macro "addtolist [a,b]" which I call like "addtolist 9,'nine'". It is supposed to append the values to some list (an EQU). Then I try to process that list using the 'table' macro, which is declared as "table [xt,nm]" but things do not work as I expect (at all). For one thing, the types of the values passed in seem wrong to me. I would appreciate any help you can provide me. Thanks!
|
|||||||||||
27 Mar 2005, 23:00 |
|
ronware 15 Jun 2005, 16:25
Arggh!
My table macro was like this: Code: macro mlist nam,xt { macrolist fix macrolist,xt,nam } And with 1.62, this doesn't work any more What is intended is that whenever 'mlist' is invoked, it adds 'name,xt' to the 'macrolist'. So that when 'macrolist' is passed to a table builder macro, it can create the proper table from it. What is the right thing to do with the new 'match', or can I still use 'fix' just in some different way? |
|||
15 Jun 2005, 16:25 |
|
Tomasz Grysztar 15 Jun 2005, 19:23
Read the updated manual, especially the section 2.3.7 which contains exactly the information you need.
|
|||
15 Jun 2005, 19:23 |
|
ronware 15 Jun 2005, 19:47
Indeed, it works! Thanks.
|
|||
15 Jun 2005, 19:47 |
|
ronware 10 Sep 2005, 01:12
Now I would like to add some more information to the list. Basically, I want to know how big the function is. Using something like this:
function 'name', _internal_name mov ebx, eax ...etc .... endfunction What I want is that 'endfunction' should figure out how big the function was (in bytes) and append that information to the function list. But sadly, I'm encountering resistance Any ideas? |
|||
10 Sep 2005, 01:12 |
|
Reverend 11 Sep 2005, 13:26
Code: macro endp name { endp sizeof.#name = $-name } ; usage: instead of lone endp add function name after it proc function1 ; normal code here endp function1 mov eax, sizeof.function1 |
|||
11 Sep 2005, 13:26 |
|
ronware 15 Sep 2005, 21:42
Thanks, I ended up doing something like that. I was hoping for something more elegant - where the current word was saved in the 'proc' macro, and reused in the 'end' macro. But I had trouble getting that part to work correctly.
|
|||
15 Sep 2005, 21:42 |
|
blueowl2 30 Oct 2005, 14:45
JohnFound wrote: Of course it is possible, with only limitation that the pointer table must stay after the last function. Should that code work? In my code there is a problem with that, namely that only one entry of the list will be written: Code: macro addtolabellist { local _label if defined labellist labellist equ labellist,_label else labellist equ _label end if _label: } macro writelabellist [label] { forward dd label } nop addtolabellist nop addtolabellist nop addtolabellist writelabellist labellist Any idea's? :) |
|||
30 Oct 2005, 14:45 |
|
Tomasz Grysztar 30 Oct 2005, 15:03
Read section 2.3.7 of manual.
|
|||
30 Oct 2005, 15:03 |
|
blueowl2 30 Oct 2005, 17:50
[quote="Tomasz Grysztar"]Read section [url=http://flatassembler.net/docs.php?article=manual#2.3.7]2.3.7[/url] of manual.[/quote]
Yes, thankyou, I already read it in your previous post. I tried it with: [code]macro addtolabellist { local _label if defined labellist labellist equ labellist,_label else labellist equ _label end if _label: } nop addtolabellist nop addtolabellist nop addtolabellist macro writelabels { match aparam, labellist \{ writelabel aparam \} } macro writelabel [tparam] { forward dd tparam } writelabels[/code] But it does not seem to replacing [i]aparam[/i] with the actual value of labellist. |
|||
30 Oct 2005, 17:50 |
|
Tomasz Grysztar 30 Oct 2005, 21:55
Go back to reading it and note what it says about mixing preprocessor's and assembler's features.
Hint: use "match", not "if". |
|||
30 Oct 2005, 21:55 |
|
blueowl2 02 Nov 2005, 19:02
Something like:
[code]V fix { macro addtolabellist \{ local _label _label: match any, labellist \\\{ labellist equ labellist,_label \\\} match , labellist \\\{ labellist equ _label \\\} \} } V nop addtolabellist nop addtolabellist nop addtolabellist macro writelabels { match aparam, labellist \{ writelabel aparam \} } macro writelabel [tparam] { forward dd tparam } writelabels[/code] :)? Sorry, I guess I need more then a hint. |
|||
02 Nov 2005, 19:02 |
|
blueowl2 03 Nov 2005, 14:21
After a lot of trying, i got the following macro working. The question is if the "definelabel" macro is necessary, or could be integrated into addtolabellist. Thanks in any case. :)
[code]macro definelabel name { name#.list equ } macro addtolabellist name { item = $ match any, name#.list \{ name#.list equ name#.list,item \} match , name#.list \{ name#.list equ item \} } definelabel some nop addtolabellist some nop addtolabellist some nop addtolabellist some macro writelabels { match aparam, some.list \{ writelabel aparam \} } macro writelabel [tparam] { forward dd tparam } writelabels[/code] |
|||
03 Nov 2005, 14:21 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.