flat assembler
Message board for the users of flat assembler.

Index > Main > local macro namespace and virtual names conflict

Author
Thread Post new topic Reply to topic
strap89



Joined: 15 Feb 2009
Posts: 23
Location: Russia
strap89 28 Feb 2009, 16:42
Hi!
Please say, what wrong in this code:
Code:
struc ST {.x db ?}
d1 ST
d2 ST
macro MC NST
{
       local dv
    virtual at d#NST
            dv ST
       end virtual
 mov eax,dv.x
}
MC 1
MC 2
    

Fasm say: dv.x undefined
But when i remove 'local dv' and 'MC 2' fasm compile OK.
Code:
struc ST {.x db ?}
d1 ST
d2 ST
macro MC NST
{
   ;local dv
   virtual at d#NST
            dv ST
       end virtual
 mov eax,dv.x
}
MC 1
;MC 2
    
P.S. i'm need remove 'MC 2' because 'dv' already defined.
Post 28 Feb 2009, 16:42
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8359
Location: Kraków, Poland
Tomasz Grysztar 28 Feb 2009, 16:44
The "dv.x" is seen by fasm as one whole name, so the "dv" local is not recognized inside it. The correct way to do it is:
Code:
struc ST {.x db ?}
d1 ST 
d2 ST 
macro MC NST 
{ 
        local dv 
        virtual at d#NST 
                dv ST 
        end virtual 
        mov eax,dv#.x
} 
MC 1 
MC 2    
Post 28 Feb 2009, 16:44
View user's profile Send private message Visit poster's website Reply with quote
strap89



Joined: 15 Feb 2009
Posts: 23
Location: Russia
strap89 28 Feb 2009, 17:11
Big thanks!
I have another small problem (similar), may it be writed in this thread?
Code:
macro DD NV {d#NV dd NV}
rept 4 counter
{
    DD counter-1
}
    
Goal is to have zero based names, but it not work.
Post 28 Feb 2009, 17:11
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 28 Feb 2009, 17:16
TFM kindly says wrote:
The counter symbol by default counts from 1, but you can declare different
base value by placing the number preceded by colon immediately after the name
of counter. For example:

rept 8 n:0 { pxor xmm#n,xmm#n }
Post 28 Feb 2009, 17:16
View user's profile Send private message Reply with quote
strap89



Joined: 15 Feb 2009
Posts: 23
Location: Russia
strap89 28 Feb 2009, 17:22
That is not complete solution:
Code:
macro DD NV {d#NV dd NV}
rept 4 counter
{
      DD counter*2
}
    
Problem returned. That is only example, i'm try understand what is it in place after #. From documentation:"It can be useful, because
it’s done after the arguments and local names are replaced with their values". So it must be a number... or not calculated expression?
Post 28 Feb 2009, 17:22
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20459
Location: In your JS exploiting you and your system
revolution 28 Feb 2009, 17:27
Code:
irp counter,0,2,4,6 { ... }    
Post 28 Feb 2009, 17:27
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: 20459
Location: In your JS exploiting you and your system
revolution 28 Feb 2009, 17:29
See here also.
Post 28 Feb 2009, 17:29
View user's profile Send private message Visit poster's website Reply with quote
strap89



Joined: 15 Feb 2009
Posts: 23
Location: Russia
strap89 28 Feb 2009, 18:09
Great examples! I'm like such code. But problem not solved:
Code:
macro pre_dec result,x {
        match xx,x { 
                rept xx j:0 { 
                        result equ j 
                \\} 
        \} 
}
macro DD NV
{
display 'NV=',NV+30h,13,10
        d#NV dd NV
}
rept 4 counter
{
    pre_dec result,counter
      mov eax,result
      DD result
}
    

It work as EQU, mov eax ,result compiled OK. But after # it not compiled. May be after # we work with expression, not with it value (may be problem come only at one of pass).
By the way, in this code compiler error is: symbol already defined, but display show different numbers, but previous code say: illegal instruction.
May be it's posiible to know: what symbol already defined. Is it d0 or d1 or d3 or may be dresult? Please, i'm try to understand rules to use such code.
Post 28 Feb 2009, 18:09
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20459
Location: In your JS exploiting you and your system
revolution 28 Feb 2009, 23:55
strap89 wrote:
compiler error is: symbol already defined
Use local to solve that problem:
Code:
local result    
Post 28 Feb 2009, 23:55
View user's profile Send private message Visit poster's website Reply with quote
strap89



Joined: 15 Feb 2009
Posts: 23
Location: Russia
strap89 01 Mar 2009, 04:24
I'm try define GLOBAL symbols with different names - local not usable.
Post 01 Mar 2009, 04:24
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20459
Location: In your JS exploiting you and your system
revolution 01 Mar 2009, 04:35
Use both local and then match to dereference "result" into the value EUQated. Or, if the list is lot too large, use irp as above.
Post 01 Mar 2009, 04:35
View user's profile Send private message Visit poster's website Reply with quote
strap89



Joined: 15 Feb 2009
Posts: 23
Location: Russia
strap89 01 Mar 2009, 05:04
In previous sample i'm ry to use EQU - it not work.
IMHO I'm understand problem: name after # resolved to there value, but resolution have only one level (nested expression no resolved).
Code:
macro A
{
  name#1 dd 0
 XF equ 1
    pame#XF dd 1
        YF fix 2
    rame#YF dd 1
        ZF fix YF
   wame#ZF dd 1
}
A
    
This code produce such names (generated by symbols.exe utility):
name1: defined in {line generated by a.asm[11] from a.asm[3]}
pameXF: defined in {line generated by a.asm[11] from a.asm[5]}
rame2: defined in {line generated by a.asm[11] from a.asm[7]}
wameXF: defined in {line generated by a.asm[11] from a.asm[9]}
1. digit converted to digit itself
2. equ not converted (it's name used). It's not shown but XF=1 work as equ.
3. fix converted to it's value
4. double fix (ZF) converted to name of previous level (YF).
Post 01 Mar 2009, 05:04
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20459
Location: In your JS exploiting you and your system
revolution 01 Mar 2009, 05:13
strap89 wrote:
(nested expression no resolved)
Did you see my last post? match can do the conversion for the values.
Post 01 Mar 2009, 05:13
View user's profile Send private message Visit poster's website Reply with quote
strap89



Joined: 15 Feb 2009
Posts: 23
Location: Russia
strap89 01 Mar 2009, 05:33
I'm see last post but i'm not understand what you meen. How dereference LOCAL name into GLOBAL namespace? Simple EQU not work.
Post 01 Mar 2009, 05:33
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20459
Location: In your JS exploiting you and your system
revolution 01 Mar 2009, 06:11
strap89 wrote:
I'm see last post but i'm not understand what you meen. How dereference LOCAL name into GLOBAL namespace? Simple EQU not work.
Code:
macro DD NV {d#NV dd NV}

macro pre_mul result,x,y {
        match xx yy,x y {
                result equ xx
                rept xx {
                        match w,result {
                                rept yy j:w {
                                        result equ j
                                \\\\}
                        \\\}
                \\}
        \}
} 

rept 400 counter:0 {
  local result
        pre_mul result,counter,2
    match r,result \{
             DD r
        \}
}

mov eax,d4
mov eax,d10
mov eax,d400    
Post 01 Mar 2009, 06:11
View user's profile Send private message Visit poster's website Reply with quote
strap89



Joined: 15 Feb 2009
Posts: 23
Location: Russia
strap89 01 Mar 2009, 12:42
Thanks!
Now i'm begin to undestand how it work. But at least at this example local is not needed, compiled ok without it. 'pre_mul' preset 'result' and not use it previous value.
Post 01 Mar 2009, 12:42
View user's profile Send private message 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.