flat assembler
Message board for the users of flat assembler.

Index > Main > struct + label with "dot" ... ?

Goto page 1, 2  Next
Author
Thread Post new topic Reply to topic
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji
Code:
struct mystruct
  .yop_1  dd ?   ; <--- with dot
  .yop_2  dd ?
ends 
    
can one do this ?
What would be the use and meaning of this ?
thank you all
Smile

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 13 Oct 2010, 18:30
View user's profile Send private message Send e-mail Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
ouadji,

Of course one can. Nothing special though: .yop_1 is a valid field name (its size will be sizeof.mystruct..yop_1, for example).
Post 14 Oct 2010, 18:27
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji
Code:
struct mystruct
  .yop_1  dd ?
  .yop_2  dd ?
ends

AA mystruct

-----> AA..yop_1 is a global label or local label ? (global for me)

    

thank you baldr.

with a "struct" or with a "struc"
is it possible to have a local label ?
or ... a label defined in "struct" (or in "struc") is always a global label ?

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 14 Oct 2010, 19:18
View user's profile Send private message Send e-mail Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
ouadji,

To have local label be defined inside struc-macro you'll need to protect leading dot with backslash(es). With struct / ends macroinstructions it's different: current implementation encloses structure body in virtual at 0 directive and collects individual data definitions/reservations in symbolic constant. Labels (as you may expect) are not handled, so they are defined inside that virtual block instead of at macro expansion.
Post 15 Oct 2010, 07:12
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji
Quote:

To have local label be defined inside struc-macro you'll need to protect leading dot with backslash(es).

ok. it's possible with "struc", but not with "struct".
about "struC + local label", please, could you give me an example.
(thank you baldr for your replies and your help)

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 15 Oct 2010, 09:38
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17630
Location: In your JS exploiting you and your system
revolution
Code:
struc point {
   \.localLabel:
  .x dw ?
     .y dw ?
}
abc point
jmp abc.localLabel    
Post 15 Oct 2010, 09:46
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7782
Location: Kraków, Poland
Tomasz Grysztar
Code:
struc mystruc
 {
   .yop_1 dd ?
   .yop_2 dd ?
 }


first:
 .local_struc mystruc ; all fields get local labels

second:
 .local_struc mystruc

        mov     eax,[.local_struc.yop_2] ; from second
        mov     eax,[first.local_struc.yop_2] ; from first    
That's not what the baldr meant, however - he proposed how can you define local label from a global structure, I hope he is going to provide some example as well. Wink
Post 15 Oct 2010, 09:50
View user's profile Send private message Visit poster's website Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji
Code:
;and this ? (I guess not)

struc point {
       \.x dw ?
        .y dw ?
}
abc point
mov eax,dword[abc.x] ;abc.x == local label ???
    

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 15 Oct 2010, 10:10
View user's profile Send private message Send e-mail Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7782
Location: Kraków, Poland
Tomasz Grysztar
Yes, in this case it will work just as it works in revolution's example - however it doesn't really make much sense to do it. You just move the moment at which "abc" is prepended to the ".x" label from preprocessor into parser - but this doesn't really affect the result. In both cases you have "abc.x" label in the end. To get any noticeable difference between the backslashed and non-backslashed one you would need a more sophisticated example.


Last edited by Tomasz Grysztar on 15 Oct 2010, 10:22; edited 2 times in total
Post 15 Oct 2010, 10:20
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17630
Location: In your JS exploiting you and your system
revolution
Code:
struc point {
   \.localLabel:
  \.x dw ?
   \.y dw ?
}

func1 point
      jmp .localLabel
     mov eax,dword[.x]

func2:
 jmp func1.localLabel
        mov eax,dword[func1.x]    
Post 15 Oct 2010, 10:20
View user's profile Send private message Visit poster's website Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji
Code:
;Can I write this in all cases: (??)

struc AA {
         .a dw ?
         .b:
        \.c:
        \.d dw ? ;db, dd, dw, .....
}
BB AA

BB.a ; global
BB.b ; global
BB.c ; local
BB.d ; local

;without "\" before == always global ?
;with "\" before    == always local ?

    

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 15 Oct 2010, 10:33
View user's profile Send private message Send e-mail Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
ouadji,

Due to the way struc-macro expands, those local labels get slightly longer full names than you're expecting: BB.b.c and BB.b.d.

----8<----
Tomasz Grysztar wrote:
I hope he is going to provide some example aswell.
I don't have slightest idea right now. They're so local. Wink
Post 15 Oct 2010, 23:02
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji

This is not a big problem.
I have a recursive function which parses very well this kind of case.

but you did not answer my question: (thank you)
Code:
struc AA {
         .a dw ?
         .b:
        \.c:
        \.d dw ? ;db, dd, dw, .....
}
BB AA

BB.a ; global
BB.b ; global
BB.c ; local
BB.d ; local 
    

(can I write this in all cases)

within a "struc" definition :

A) without "\" before == always global ?
B) with "\" before == always local ?

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 15 Oct 2010, 23:38
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17630
Location: In your JS exploiting you and your system
revolution
ouadji: If you manually expand the struc macro then you will see what happens.

BB AA expands to:
Code:
BB.a dw ? ;<--- a global label
BB.b:     ;<--- a new global label
.c:       ;<--- it is local to the previous global label, i.e. it is BB.b.c
.d dw ?   ;<--- BB.b.d    
Post 16 Oct 2010, 00:30
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17630
Location: In your JS exploiting you and your system
revolution
So if you want to make the labels BB.c and BB.d then change the struc:
Code:
struc AA {
         .a dw ?
         .b:
         .#c:
         .#d dw ?
}
BB AA    
But you gain nothing over a normal struc:
Code:
struc AA {
         .a dw ?
         .b:
         .c:
         .d dw ?
}
BB AA    
Post 16 Oct 2010, 00:38
View user's profile Send private message Visit poster's website Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 3018
Location: vpcmipstrm
bitRAKE
All labels are global, the dot scheme just allows shortcuts to be used:
Code:
XX.abc dw 5

XX:
  mov ax,[.abc]    
@@ might be the only truly local label? (I haven't looked into how FASM handles it - maybe there is a way to get some pseudo-name and use it globally?)
Post 16 Oct 2010, 01:57
View user's profile Send private message Visit poster's website Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17630
Location: In your JS exploiting you and your system
revolution
bitRAKE wrote:
All labels are global, the dot scheme just allows shortcuts to be used:
Code:
XX.abc dw 5

XX:
  mov ax,[.abc]    
That is not the same as a "true" local label.

Consider:
Code:
XX: ;global. Changes the base name to XX
  .bcd dw 1 ;.bcd as local. XX.bcd as global

XX.abc dw 2 ;global. Changes the base name to XX.abc
  .bcd dw 3 ;.bcd as local. XX.abc.bcd as global    
The difference being the local labels do not change the base global label name for the next local label.
Post 16 Oct 2010, 03:03
View user's profile Send private message Visit poster's website Reply with quote
baldr



Joined: 19 Mar 2008
Posts: 1651
baldr
ouadji,

Is this question related to Wink development? I'm asking just to be sure I'm not taking the wrong route: in general case you should preprocess/interpret source to be sure what does symbol exactly mean.
Code:
macro A.c x { struc b \{ x \} }
struc a {
  .b db 1
  .c db 2
  .d db 3
}
A a
B b
C a    
Post 16 Oct 2010, 09:53
View user's profile Send private message Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji

Quote:
The difference being the local labels do not change the base global label name for the next local label.
ok, i understood, here is the key of this problem.


just for the fun, Razz
Code:
struc AA1 {
   .x:
  \.y:
}
.BB1 AA1
jmp .BB1.x.y   ;does not compile

;is ".BB1.x.y" unattainable ?

;---------------------------------------------

struc AA1 {
   .x:
  \.y:
}
BB1 AA1
jmp BB1.x.y   ;does compile 
    

Tomasz,when will we have a true doc about macros ?
Why this must remain the gods secret !!
(thank you)

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 16 Oct 2010, 10:01
View user's profile Send private message Send e-mail Reply with quote
ouadji



Joined: 24 Dec 2008
Posts: 1081
Location: Belgium
ouadji
Quote:
Is this question related to Wink development ?
yes, of course.
Code:
macro A.c x { struc b \{ x \} }
struc a {
  .b db 1
  .c db 2
  .d db 3
}
A a
B b
C a
    
my god, how horrible! Shocked Shocked
I will never have the time to parse this kind of complex case in real time.
Quote:
in general case you should preprocess/interpret source to be sure what does symbol exactly mean.
I think it is impossible to do that in real time.
I have only the time between two keystrokes on the keyboard,
(repeat keystrokes ... 0,1 sec... max 0,2 sec!)
I don't have time to do what I want. Sad
I have to make choices, it's inescapable !

_________________
I am not young enough to know everything (Oscar Wilde)- Image
Post 16 Oct 2010, 10:09
View user's profile Send private message Send e-mail Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page 1, 2  Next

< 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. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.