flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > force evaluation

Author
Thread Post new topic Reply to topic
Smile



Joined: 07 May 2006
Posts: 6
Smile 08 May 2006, 21:24
Hi

used compiler fasm-1.64

Code:
macro MakeName name, i
{
 name#i = '?'
}
index = 0
MakeName _, index 
    


Prefer result "_0" label instead of "_index".
Is it possible to evaluate "index" before concatenation?
Post 08 May 2006, 21:24
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 08 May 2006, 22:04
Code:
macro MakeName name, i
{
  match index, i \{
    name \# index = '?'
  \}
} 

index equ 0
MakeName _, index

display _0    


I don't remember why match is needed but works Very Happy

Note I use equ instead of =, you need to use equ because the # works at preprossesing time (where "=" works at assembly time)

Hope this helps and someone explain us why match is needed Laughing
Post 08 May 2006, 22:04
View user's profile Send private message Reply with quote
Smile



Joined: 07 May 2006
Posts: 6
Smile 08 May 2006, 22:39
"index equ 0" - constant expression, and not work in my case

Code:
index = 0 ; <- dinamic expression
MakeName _, index+1
    


i use this construction to access stored variables, have i another way?

Code:
macro stack name
{
 common
  name#.sp = 0 ; stack pointer

  macro name#.push arg
  \{
   index = name#.sp
   name#.item#index = arg
   name#.sp = index + 1
  \}

  macro name#.pop  arg
  \{
   index = name#.sp
   if index > 0
    arg = name#.item#index
    name#.sp = index - 1
   else
    display `name # ' - stack is empty'
   end if
  \}
}

stack s
s.push 1
s.pop x
display x+0x30   
    


main problem - resolve unique names
Code:
name#.item#index ; always s.itemindex
    
Post 08 May 2006, 22:39
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 08 May 2006, 23:03
Check this http://board.flatassembler.net/topic.php?p=29109#29109

To decrement if there is no other way you can get it by doing
Code:
restore counter
restore counter    


I think you can use equates with your problem but I have no time to do it now. I'll try later if you still having problems

Regards
[edit]Works but not checked if it does all that is intended
Code:
macro stack name
{ 
 common 
  name#.sp = 0 ; stack pointer 
  index equ 0

  macro name#.push arg 
  \{ 
    match current,index ; this we need to get value of index before preprocessing
    \\{
       name\\#.item\\#current = arg

       rept 2 i:current \\\{ index equ i \\\} ; this increases the index
    \\}
   name#.sp = index
  \}

  macro name#.pop  arg
  \{ 
   if index > 0
    restore index
    restore index
    name#.sp = index
    match current,index ; this we need to get value of index before preprocessing
    \\{
      arg = name\\#.item\\#current
    \\}
   else
    display `name # ' - stack is empty'
    err
   end if 
  \} 
}

stack test

irp item, 'H', 'e', 'l', 'l', 'o' {test.push item}

rept 5 n:0 { display test.item # n }
display 13, 10

rept 5 n:0
{
  test.pop char
  display char
}    
Post 08 May 2006, 23:03
View user's profile Send private message Reply with quote
Smile



Joined: 07 May 2006
Posts: 6
Smile 09 May 2006, 08:26
locodelassembly
Thank
Post 09 May 2006, 08:26
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 09 May 2006, 13:37
I forgot to say something, don't use things like
Code:
 repeat test.sp
test.pop item
end repeat    
and the others iterative structures of the assembly stage because both push and pop need to be expanded for every call to it.

See why:
Code:
repeat test.sp
  test.pop var
  display var ; Five o's will be displayed
end repeat    


Preprocesed as:
Code:
repeat test.sp
;test.pop var
        
        if 5>0
        ;restore index
        ;restore index
        test.sp=4
        ;match current,4
        ;{
        ; var=test#.item#current
        ;}
        
        var=test.item4
        
        else
        display 'test - stack is empty'
        err
        end if
        
display var
end repeat     

As you can see, index is decremented only once (since repeat doesn't repeats "restore index" nor concatenates again with # since that is at preprossesing stage).

As a rule, always make sure that push and pop gets expanded every time it's used (like REPT does).
Post 09 May 2006, 13:37
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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.