flat assembler
Message board for the users of flat assembler.
Index
> Macroinstructions > Placing functions to symbol table |
Author |
|
sid123 07 Jan 2015, 07:46
Hello, I am writing code that needs to be assembled to my own format, and I am currently stuck with creating a symbol table.
Basically a symbol inside the symbol table is sort of like this: Code:
uint8_t* SymbolName
uint32_t SymbolAddress
uint32_t SymbolEnd
I currently have this: Code: macro function label, symbol { ; Some function prologue.... .... ;;;;;;;;;;;;;;;;;;;;;;; local symnameaddr ; rev's list building macros .data \{ symnameaddr: db symbol, 0 \} .symbol \{ dd symnameaddr dd label# ;; How can I get the end of this function? ;; Something like: dd label#_end \} #label: } It works, but how can I get the end of a symbol? (As in the end of the function) Something along the lines of : Code: function myfunction, "myfunction" ...... endfunction ; There should be a label created here as "myfunction_end:" Also is there anyway I can store the label as a string? _________________ "Those who can make you believe in absurdities can make you commit atrocities" -- Voltaire https://github.com/Benderx2/R3X XD |
|||
07 Jan 2015, 07:46 |
|
baldr 07 Jan 2015, 10:09
sid123,
Symbol inside macroblock can be converted to quoted string using backquote (`, AKA backtick or grave accent) operator. In your endfunction macro you may refer to some symbolic constant defined in function macro that holds label argument value (you might need to expand that symbolic constant with match because macro operators take precedence over symbolic constants expansion). ----8<---- revolution, Macro-local symbols are, as the name implies, local to enclosing macroblock. endfunction macro can be defined inside function macro block, but purge can't be used to drop that definition from within endfunction due to scope. |
|||
07 Jan 2015, 10:09 |
|
l_inc 07 Jan 2015, 12:51
baldr
Quote: endfunction macro can be defined inside function macro block, but purge can't be used to drop that definition from within endfunction due to scope The best way I came up with to deal with this problem is to enclose both definitions of co-macros into a common macroblock such as match,{} or rept 1{}. It is possible to use a purge based approach as well, but the architecture would become uglier and would require more preprocessing (and hence more memory and time). Quote: you might need to expand that symbolic constant with match because macro operators take precedence over symbolic constants expansion I don't see any need in applying macro operators to the symbolic constant: Code: rept 1 { local sym macro fun lbl* \{ sym equ lbl\#_end \} macro endf \{ sym: \} } fun my endf _________________ Faith is a superposition of knowledge and fallacy |
|||
07 Jan 2015, 12:51 |
|
baldr 08 Jan 2015, 16:26
l_inc wrote: I don't see any need in applying macro operators to the symbolic constant As a side note, macroblock alone might be useful extension of fasm syntax (I mean {} without always-match or rept 1 or similar kludge). I'll look into that. |
|||
08 Jan 2015, 16:26 |
|
l_inc 08 Jan 2015, 17:11
baldr
Quote: Inside your endf macro ... it's crucial to expand sym to get proper `sym value Or one could just push both the label and its string representation onto the sym stack in the fun macro (I actually missed a restore, which is important to have, especially for nesting co-macros). But it was a bit of too much nitpicking from my part, because you actually said: "... you might need to expand ..." Quote: I mean {} without always-match or rept 1 or similar kludge This kludge doesn't actually make one's life more complicated. So I don't mind using them. What I'm not sure about is whether "match," or "rept 1" is better. I got used to the former but feel like the latter could have some pros (e.g., in terms of having less overhead). _________________ Faith is a superposition of knowledge and fallacy |
|||
08 Jan 2015, 17:11 |
|
revolution 09 Jan 2015, 00:29
Note that ASM uses {} for register lists. I would be against such an addition because it is used almost never and would break other code.
|
|||
09 Jan 2015, 00:29 |
|
< Last Thread | Next Thread > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.