flat assembler
Message board for the users of flat assembler.

Index > Main > label namespace difference in fasmg

Author
Thread Post new topic Reply to topic
donn



Joined: 05 Mar 2010
Posts: 321
donn 23 Oct 2018, 13:51
Hi, I'm having some simple namespace problems in fasmg. The labels I'm using within functions are not working within the namespace the same way they were within fasm1. They must be declared as absolute, possibly because of my 'stack labels':

Code:
list.getNextItemMatch:
        push rbp 
        mov rbp, rsp 
        sub rsp, (8*8)


        label list.getNextItemMatch.heapAddress qword at rbp-8  
        label list.getNextItemMatch.handleAllocatedMemory qword at rbp-16
        label list.getNextItemMatch.list qword at rbp-24 
        label list.getNextItemMatch.item qword at rbp-32
        label list.getNextItemMatch.prevItem qword at rbp-40
        label list.getNextItemMatch.prevItemIndex qword at rbp-48
        label list.getNextItemMatch.itemMatch qword at rbp-56
        label list.getNextItemMatch.listItemMatch qword at rbp-64    


Code:
...
        list.getNextItemMatch.noMatch:    


instead of

Code:
...
        .noMatch:    



I tried the label . thing, but it errored:


Code:
Processed: label .
Error: definition in conflict with already defined symbol.    


upon assembly. This is a very menial problem, but it would save a lot of typing and allow me to assemble some old fasm1 files with fasmg. I'll figure this out soon, but was curious if there was an easy fix.
Post 23 Oct 2018, 13:51
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 23 Oct 2018, 14:28
The starting dot in fasmg is defined as referring to a child of the most recent label in the current namespace. The "getNextItemMatch" is a label in "list" namespace, so it does not become a parent for labels starting with dot unless you switch to "list" namespace. In this case this would look like:
Code:
namespace list

        label .heapAddress qword at rbp-8
        label .handleAllocatedMemory qword at rbp-16
        label .list qword at rbp-24
        label .item qword at rbp-32
        label .prevItem qword at rbp-40
        label .prevItemIndex qword at rbp-48
        label .itemMatch qword at rbp-56
        label .listItemMatch qword at rbp-64

end namespace    


However, to make the code more clear it would probably be better to define it like:
Code:
namespace list

    getNextItemMatch:

        push rbp
        mov rbp, rsp
        sub rsp, (8*8)

        label .heapAddress qword at rbp-8
        label .handleAllocatedMemory qword at rbp-16
        label .list qword at rbp-24
        label .item qword at rbp-32
        label .prevItem qword at rbp-40
        label .prevItemIndex qword at rbp-48
        label .itemMatch qword at rbp-56
        label .listItemMatch qword at rbp-64

end namespace    
or even:
Code:
namespace list

    getNextItemMatch:

    namespace getNextItemMatch

        push rbp
        mov rbp, rsp
        sub rsp, (8*8)

        label heapAddress qword at rbp-8
        label handleAllocatedMemory qword at rbp-16
        label list qword at rbp-24
        label item qword at rbp-32
        label prevItem qword at rbp-40
        label prevItemIndex qword at rbp-48
        label itemMatch qword at rbp-56
        label listItemMatch qword at rbp-64

    end namespace

end namespace    
Post 23 Oct 2018, 14:28
View user's profile Send private message Visit poster's website Reply with quote
donn



Joined: 05 Mar 2010
Posts: 321
donn 23 Oct 2018, 15:06
Perfect, the second one seems to make the most logical sense:

Code:
namespace list

getNextItemMatch:

        push rbp 
…
        label .heapAddress qword at rbp-8  
        label .handleAllocatedMemory qword at rbp-16
        label .list qword at rbp-24 
        label .item qword at rbp-32
...
        .noMatch:

        add rsp, 8      
        pop r15 
        pop r14 
        pop r13 
        pop r12 
        pop rsp 
        pop rsi 
        pop rdi 
        pop rbp 
        pop rbx

        mov rsp, rbp
        pop rbp

        retn 0
end namespace
    



and assembles. It would also allow me to use old fasm1 files with few changes. The last example without the dot is cool, may look into that soon. Really liking the namespace keyword. Copy and pasting long namespace names can really slow down productivity.
Post 23 Oct 2018, 15:06
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 12 Mar 2019, 14:40
Important note: I later decided to change the starting-dot rules to be more compatible with fasm 1 and now even the approach that did not work for you (described in the initial post here) would behave as you originally expected.
Post 12 Mar 2019, 14:40
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-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.