flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Placing functions to symbol table

Author
Thread Post new topic Reply to topic
sid123



Joined: 30 Jul 2013
Posts: 339
Location: Asia, Singapore
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
Post 07 Jan 2015, 07:46
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 07 Jan 2015, 09:17
IIRC you can do it like this (untested):
Code:
macro function name,[args] {
        common
        local endfunction@name
        endfunction@name equ name#_end
        ;...
}
macro endfunction {
        endfunction@name:
}    
Post 07 Jan 2015, 09:17
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
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.
Post 07 Jan 2015, 10:09
View user's profile Send private message Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
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
Post 07 Jan 2015, 12:51
View user's profile Send private message Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr 08 Jan 2015, 16:26
l_inc wrote:
I don't see any need in applying macro operators to the symbolic constant
I said that because sid123 didn't specify where he want to convert that label to quoted string. Inside your endf macro (effectively you simply generate probably unique name for an aforementioned symbolic constant, isn't it?) it's crucial to expand sym to get proper `sym value.

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.
Post 08 Jan 2015, 16:26
View user's profile Send private message Reply with quote
l_inc



Joined: 23 Oct 2009
Posts: 881
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
Post 08 Jan 2015, 17:11
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
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.
Post 09 Jan 2015, 00:29
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.