flat assembler
Message board for the users of flat assembler.

Index > Main > 'out of scope' why?

Author
Thread Post new topic Reply to topic
xRom



Joined: 26 Apr 2011
Posts: 13
xRom 06 Nov 2011, 20:51
Why this code compiling normally
Code:
struc     _win x,y {
          %w        = $
               .1   dw        x
               .2   dw        y     
          %w1 = $ - %w  
          
}     

          mov       eax,%w1
          
section '.data' data readable writeable
w3        _win      10,20 ;one defined
    

But this - no?
Code:
struc     _win x,y {
          %w        = $
               .1   dw        x
               .2   dw        y     
          %w1 = $ - %w
          
}     

          mov       eax,%w1
          
section '.data' data readable writeable
w3        _win      10,20    ;one defined
w4        _win      20,30    ;two defined
    

FASM error message:
Quote:

mov eax,%w1
error: symbol '%w1' out of scope.
Post 06 Nov 2011, 20:51
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 06 Nov 2011, 20:55
are you sure the second code really has "mov eax,w3.%w1"? The error code only says "mov eax,%w1".
Post 06 Nov 2011, 20:55
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 06 Nov 2011, 20:56
Use the dot.
Code:
.%w        = $
;...
.%w1 = $ - .%w    


BTW: Your first code does not compile normally: error: undefined symbol 'w3.%w1'
Post 06 Nov 2011, 20:56
View user's profile Send private message Visit poster's website Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid 06 Nov 2011, 20:57
You edited your post while I was typing my previous answer, disregard it. For answer to your question, read http://flatassembler.net/docs.php?article=manual#1.2.3
Post 06 Nov 2011, 20:57
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
xRom



Joined: 26 Apr 2011
Posts: 13
xRom 06 Nov 2011, 20:59
vid wrote:
are you sure the second code really has "mov eax,w3.%w1"? The error code only says "mov eax,%w1".

Sorry, a'm corrected. But still don't work.
Post 06 Nov 2011, 20:59
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 06 Nov 2011, 21:03
The reason you get out of scope is because you are defining %w1 and later redefining %w1 again. You can't forward reference variables that are redefined. Use the dot like I showed above.
Post 06 Nov 2011, 21:03
View user's profile Send private message Visit poster's website Reply with quote
xRom



Joined: 26 Apr 2011
Posts: 13
xRom 06 Nov 2011, 21:23
revolution wrote:
The reason you get out of scope is because you are defining %w1 and later redefining %w1 again. You can't forward reference variables that are redefined. Use the dot like I showed above.

Greate thanks, but if I can not use the name of the structure in this case (which I do not know beforehand)? how calculate the offset fields inside the structure so as not to write later in the procedure:

mov eax,[ebp+10]

and write

mov eax,[ebp+%window.size]

for example? If procedure is one, and macro 'window' are two? or more?
Post 06 Nov 2011, 21:23
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 06 Nov 2011, 21:35
If you want the size of the structure use this:
Code:
struc _win x,y {
 .1      dw      x
   .2      dw      y          
}
virtual
    _win _win 0,0
       _win.size = $-$$
end virtual

;...

mov eax,_win.size    
Post 06 Nov 2011, 21:35
View user's profile Send private message Visit poster's website Reply with quote
xRom



Joined: 26 Apr 2011
Posts: 13
xRom 07 Nov 2011, 06:46
revolution wrote:

virtual
_win _win 0,0
_win.size = $-$$
end virtual
;...
mov eax,_win.size[/code]

Thanx! This is work. But i'm not understand why Embarassed
Post 07 Nov 2011, 06:46
View user's profile Send private message Reply with quote
goldenspider



Joined: 16 May 2011
Posts: 38
goldenspider 07 Nov 2011, 07:32
Or you can use struct.
Code:
struct   _win
    1   dw  ?
    2   dw  ?
ends

...
     movzx eax,[w3.1]
     mov   eax,sizeof._win
     mov   eax,sizeof._win.1

...
w3 _win 10,20    
Post 07 Nov 2011, 07:32
View user's profile Send private message Reply with quote
xRom



Joined: 26 Apr 2011
Posts: 13
xRom 07 Nov 2011, 08:24
goldenspider wrote:
Or you can use struct.
w3 _win 10,20[/code]

thanx! it's work. but what is it - struct? in manual http://flatassembler.net/docs.php?article=manual#2.3.4 - no about this...
Post 07 Nov 2011, 08:24
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20451
Location: In your JS exploiting you and your system
revolution 07 Nov 2011, 08:30
xRom wrote:
thanx! it's work. but what is it - struct? in manual http://flatassembler.net/docs.php?article=manual#2.3.4 - no about this...
It is a macro, not a directive. You can see the definition in 'macro\struct.inc'. And the documentation is here
Post 07 Nov 2011, 08:30
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.