flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > I play with irpv. I not clear undertstood irpv.

Author
Thread Post new topic Reply to topic
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 27 Jan 2019, 03:17
In some tread Tomasz write me this macro.
Code:
macro apply [v] {
       define  __applied v
       v equ template.#v
       v                       ;i write this and get work

}

macro end.apply {
       irpv v,__applied \{
                restore v
                restore __applied

       \}
} 
    

I try do this:
Code:
template.regstr EQU EBP
template.z2 EQU [template.regstr+8]
template.zh EQU  mov template.z2,eax
 
template.regstr EQU ESI  ;some times i need change register to ESI or EBP or EDI. 
apply zh
end.apply

template.regstr EQU EDI 
apply zh
end.apply
    

IDA Pro show mov [ebp+8],eax and mov [ebp+8],eax
But i expect mov [esi+8],eax and mov [edi+8],eax


Last edited by Roman on 27 Jan 2019, 03:36; edited 4 times in total
Post 27 Jan 2019, 03:17
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1878
Roman 27 Jan 2019, 03:25
And i not understood why irpv use v and __applied.
I read fasm pdf but little information about irpv.
And not full irpv explanation.
Post 27 Jan 2019, 03:25
View user's profile Send private message Reply with quote
QuarkMan



Joined: 21 Sep 2019
Posts: 6
Location: Suzano - São Paulo - Brasil
QuarkMan 21 Sep 2019, 15:33
You need to preprocess the symbol "template.z2" again, I think...
Post 21 Sep 2019, 15:33
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 21 Sep 2019, 16:14
Your problem is not related to IRPV, it is about the difference between EQU and DEFINE.

With EQU you have symbolic variables expanded within the text before the assignment:
Code:
template.regstr EQU EBP
template.z2 EQU [template.regstr+8] ; the value is: [EBP+8]
DEFINE template.z2 [template.regstr+8] ; the value is: [template.regstr+8]    


The other problem is that in fasm 1 (as opposed to fasmg) the processing of symbolic variables is never recursive, so if "template.z2" is replaced with "[template.regstr+8]", no further replacement of "template.regstr" is done.

To get around this, you need to add another pass of replacements, like this:
Code:
macro apply [v] {
       define  __applied v
       v equ template.#v
       match vv, v \{ ; do additional pass of symbolic variable replacements
               vv
       \}
}    
And then define your template like:
Code:
template.regstr EQU EBP
DEFINE template.z2 [template.regstr+8]
template.zh EQU mov template.z2,eax     ; the value is: mov [template.regstr+8],eax    


If you needed even more layers, for example if you used DEFINE in both places:
Code:
template.regstr EQU EBP
DEFINE template.z2 [template.regstr+8]
DEFINE template.zh mov template.z2,eax     
you are going to need even more passes of replacements to peel off all the layers:
Code:
macro apply [v] {
       define  __applied v
       v equ template.#v
       match vv, v \{
               match vvv, vv \\{
                       vvv
               \\}
       \}
}    
Post 21 Sep 2019, 16:14
View user's profile Send private message Visit poster's website Reply with quote
QuarkMan



Joined: 21 Sep 2019
Posts: 6
Location: Suzano - São Paulo - Brasil
QuarkMan 21 Sep 2019, 17:23
Since we are talking about IRPV, I would like to take the time to solve the problem in this file.
I don't understand why IRPV resolves the "super.cName\#.FinalVariables" symbol and also shows the contents of the "super.cName\#.StaticVariables" symbol.


Description:
Download
Filename: Ampere.inc
Filesize: 2.41 KB
Downloaded: 632 Time(s)

Post 21 Sep 2019, 17:23
View user's profile Send private message Reply with quote
QuarkMan



Joined: 21 Sep 2019
Posts: 6
Location: Suzano - São Paulo - Brasil
QuarkMan 21 Sep 2019, 18:06
I ended up modifying a piece of code to the following:
Code:
class Object:
{
    
    Object.StaticVariables equ A
    Object.FinalVariables equ B
    Object.FinalVariables equ C
    
}
    


And miraculously it worked the way it should. Laughing
It seems that the problem isn't wiht IRPV, but the MACRO "int", inside the "if" statement.

But, strangely, even with the previous code, the "Display" inside "if" seems to work perfectly. Question
Post 21 Sep 2019, 18:06
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8367
Location: Kraków, Poland
Tomasz Grysztar 21 Sep 2019, 18:14
QuarkMan wrote:
Since we are talking about IRPV, I would like to take the time to solve the problem in this file.
I don't understand why IRPV resolves the "super.cName\#.FinalVariables" symbol and also shows the contents of the "super.cName\#.StaticVariables" symbol.

In fasm 1 EQU is not affected by IF directive, because EQU is a directive of preprocessor, so all EQU definitions and macros are already processed away at the time when the assembler sees the IF directive (see a thread about fasm's layers for a bit of context).

Therefore in your macro "int" both EQU definitions end up being actually defined, because preprocessor does not see or understand IF.
Post 21 Sep 2019, 18:14
View user's profile Send private message Visit poster's website Reply with quote
QuarkMan



Joined: 21 Sep 2019
Posts: 6
Location: Suzano - São Paulo - Brasil
QuarkMan 21 Sep 2019, 19:01
Oh, thanks. I'll try to do this in other way.
Post 21 Sep 2019, 19:01
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.