flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Virtual registers. How do ?

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



Joined: 21 Apr 2012
Posts: 1821
Roman 29 Jul 2020, 20:05
Code:
VR1 EQU eax
VR2 EQU ebx
VR3 EQU edx
VR4 EQU ecx
VR5 EQU esi
VR6 EQU edi
VR7 EQU [tmp1] 
VR8 EQU [tmp2] 

CurVR EQU VR
MacroL 10 ;do this VR+1 and get mov VR1,10
MacroL 21 ;do this VR1+1 and get mov VR2,21
MacroL 1 ;do this VR2+1 and get mov VR3,1
MacroL 31 ;do this VR3+1 and get mov VR4,31
    


macro MacroL must increase CurVR+1.
And if CurVR = VR6 then CurVR = VR
Post 29 Jul 2020, 20:05
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1821
Roman 30 Jul 2020, 07:10
I write but not shoore its good solution or not.
I test on IDA Pro work fine.
Code:
VR1    EQU eax
VR11    EQU ebx
VR111    EQU edx
VR1111    EQU ecx
VR11111    EQU esi
VR111111    EQU edi
VR1111111    EQU [tmpVR1]
VR11111111    EQU [tmpVR2]
VR111111111    EQU [tmpVR3]
VR1111111111    EQU [tmpVR4]
VR11111111111    EQU [tmpVR5]
VR111111111111    EQU [tmpVR6]
VR1111111111111    EQU [tmpVR7]
CurVR   EQU VR
ozzVR   EQU 0

macro CyclVR   { local i       
       CurVR EQU CurVR\#1       
       match aa,CurVR \{ mov  aa,2
       \}
   LB_#i:  ozzVR EQU LB_#i      }

macro VRLoop {
     match aa,CurVR \{ dec  aa
           cmp aa,0           \}      
      jnz ozzVR
         restore ozzVR
         restore CurVR
      }

section '.code' code readable writeable executable
        gre  dd 110
        fur  dd 0
        freq dd 0
        rept 10 n:1 { tmpVR#n dd 0 }

start:
         CyclVR
         CyclVR
         CyclVR
         CyclVR
         CyclVR
         CyclVR
         CyclVR
         CyclVR
         CyclVR

         VRLoop
         VRLoop
         VRLoop
         VRLoop
         VRLoop
         VRLoop
         VRLoop
         VRLoop
         VRLoop            
    
Post 30 Jul 2020, 07:10
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 30 Jul 2020, 08:48
Feels like you’re doing something really strange. What’s your real goal?
Post 30 Jul 2020, 08:48
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1821
Roman 30 Jul 2020, 09:39
No need to think about which register to write.

This method set auto register.
And no need write labels.
This method good for some individual utelites. Utelite out txt code.
Profit

PS: If write code for ARM , this good because easy change VR1 registers.
Or 32 bits code change\rewrite for 64 bits(registers R8\R9\R10\R11\R12\R13\R14\R15).


Last edited by Roman on 30 Jul 2020, 10:11; edited 2 times in total
Post 30 Jul 2020, 09:39
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1821
Roman 30 Jul 2020, 10:01
I not realy like so long names VR1111111111111.
How fix this ?
Post 30 Jul 2020, 10:01
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 1228
Location: Belarus
DimonSoft 30 Jul 2020, 11:50
It is going to turn out to be a leaky abstraction as soon as your
Code:
mov vr10, vr11    
translates into
Code:
mov [tmpVR10], [tmpVR11]    

If you expect this to become a cross-platform solution, you’re about to fail. Just think about other limitations of different architectures and just plain corner cases:
Code:
mov vr0, [vr10]    
becomes
Code:
mov eax, [[tmpVR10]]    
not to mention
Code:
mov vr0, [vr0]    
which might be a perfectly valid
Code:
mov eax, [eax]    
code piece with 32-bit addressing and an impossible
Code:
mov ax, [ax]    
code piece with 16-bit addressing.

I don’t think there’s an easy solution for what you ask for. But I’d think twice if you really need that.
Post 30 Jul 2020, 11:50
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1821
Roman 30 Jul 2020, 11:59
I'm not saying my solution is perfect.

I'm just discussing this.
And maybe something better to come up with this.
I dont know.

Code:
Not good: mov vr10, vr11 ;get mov [tmpVR10], [tmpVR11]

Good: macro VR10,VR11 ;get movss xmm1, VR11 and movss VR10,xmm1
    


Macro must translete to movss xmm1, VR11 and movss VR10,xmm1
Macro might get type. Is this register or [register]
Code:

macro VRMov chA,chB {
      if chA eqtype reg & chB eqtype reg
      movss xmm1,[chB]
      movss [chA],xmm1
      end if
      if chA eqtype [] & chB eqtype []
      movss xmm1,chB
      movss chA,xmm1
      end if
      if chA eqtype [] & chB eqtype reg
      movss xmm1,[chB]
      movss chA,xmm1
      end if
      if chA eqtype reg & chB eqtype []
      movss xmm1,chB
      movss [chA],xmm1
      end if
      } 
In code:
VR_7  EQU VR1111111
VR_8  EQU VR11111111
VRMov  VR_7,VR_8
    

I tested now. Work
Post 30 Jul 2020, 11:59
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1821
Roman 31 Jul 2020, 07:30
How do this ?
Code:
macro VRPush { local i
      i = VR_cnttz
      if VR_cnttz > 0
      i = i - 1
      push VR_#i
      end if
      } 
    

Fasm get error undefined symbol VR_i
I want get this:
push VR_5
push VR_4
push VR_3
push VR_2
push VR_1
Post 31 Jul 2020, 07:30
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20401
Location: In your JS exploiting you and your system
revolution 31 Jul 2020, 07:40
You can't mix assembler =, if, etc. and preprocessor macros like that.

Use rept
Code:
VR_cnttz equ 5
rept VR_cnttz i {
  reverse
  push VR_#i
}    
Post 31 Jul 2020, 07:40
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1821
Roman 31 Jul 2020, 07:51
Thanks revolution

But i have litle problem.
VR_cnttz = 5
And rept VR_cnttz i {
reverse
push VR_#i
}
Get me error invalid value


Last edited by Roman on 31 Jul 2020, 07:56; edited 1 time in total
Post 31 Jul 2020, 07:51
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20401
Location: In your JS exploiting you and your system
revolution 31 Jul 2020, 07:53
You can't use = there. You have to use EQU because it is a preprocessor value.
Post 31 Jul 2020, 07:53
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1821
Roman 31 Jul 2020, 07:59
CyclVR now work fine. And i need VR_cnttz
Code:
macro CyclVR chNum  { local i      
       CurVR EQU CurVR\#1
       match aa,CurVR \{ mov  aa,chNum
       \}
   LB_#i:  ozzVR EQU LB_#i
      VR_cnttz = VR_cnttz + 1
      }
    

How i can do EQU (get VR_cnttz for rept) in this case ?


Last edited by Roman on 31 Jul 2020, 08:14; edited 1 time in total
Post 31 Jul 2020, 07:59
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20401
Location: In your JS exploiting you and your system
revolution 31 Jul 2020, 08:13
Use rept again:
Code:
VR_cnttz equ 0
;...
rept 2 x:VR_cnttz {VR_cnttz equ x} ; increment VR_cnttz    
Post 31 Jul 2020, 08:13
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1821
Roman 31 Jul 2020, 08:37
I put rept 2 x:VR_cnttz {VR_cnttz equ x} in macro CyclVR:
Code:
VR_cnttu EQU 0 ;do this one time ! 
macro CyclVR chNum  { local i      
       CurVR EQU CurVR\#1      
       match aa,CurVR \{ mov  aa,chNum
       \}
   LB_#i:  ozzVR EQU LB_#i
      VR_cnttz = VR_cnttz + 1
      rept 1 x:VR_cnttu \{ VR_cnttu equ x \}
      }
    

In code i do only two CyclVR, but get VR_cnttu = 0 !

I rewrite
Code:
VR_cnttu EQU 0 ;do this one time ! 
macro CyclVR chNum  { local i      
       CurVR EQU CurVR\#1      
       match aa,CurVR \{ mov  aa,chNum
       \}
   LB_#i:  ozzVR EQU LB_#i
      VR_cnttz = VR_cnttz + 1
      rept 2 x:VR_cnttu \{ VR_cnttu equ x \}
      }
    

Now i do two CyclVR and get VR_cnttu = 2
Post 31 Jul 2020, 08:37
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20401
Location: In your JS exploiting you and your system
revolution 31 Jul 2020, 09:17
"rept 2 ..." is the correct value to increment by 1
Post 31 Jul 2020, 09:17
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: 20401
Location: In your JS exploiting you and your system
revolution 31 Jul 2020, 09:20
I think this also works:
Code:
rept 1 x:VR_cnttz+1 {VR_cnttz equ x}  ; increment VR_cnttz    
Post 31 Jul 2020, 09:20
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1821
Roman 31 Jul 2020, 12:13
Quote:
rept 1 x:VR_cnttz+1 {VR_cnttz equ x} ; increment VR_cnttz

Yes its work. I test.


Last edited by Roman on 31 Jul 2020, 12:16; edited 1 time in total
Post 31 Jul 2020, 12:13
View user's profile Send private message Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1821
Roman 31 Jul 2020, 12:16
Another problem. Not work If
Code:
macro VRPush {
rept VR_cnttu ri \{
  if VR_\#ri eqtype reg
  reverse
  push VR_\#ri
  end if
  \}
      }
    


Must do push eax\ebx\edx\ecx\esi\edi
But get nothing.
Without if work fine.


Last edited by Roman on 31 Jul 2020, 12:18; edited 1 time in total
Post 31 Jul 2020, 12:16
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20401
Location: In your JS exploiting you and your system
revolution 31 Jul 2020, 12:17
"reg" is not a type. Perhaps you mean "eax" which is a register.
Post 31 Jul 2020, 12:17
View user's profile Send private message Visit poster's website Reply with quote
Roman



Joined: 21 Apr 2012
Posts: 1821
Roman 31 Jul 2020, 12:19
Yes. Your right.
I write if VR_\#ri eqtype eax now work how i expected.

Another strange thing:
Work fine.
Code:
rept VR_cnttu ri \{
 reverse
  if VR_\#ri eqtype eax 
push VR_\#ri
end if \}
    


But not work correct:
Code:
rept VR_cnttu ri \{
  if VR_\#ri eqtype eax 
reverse
push VR_\#ri
end if \}
    
Post 31 Jul 2020, 12:19
View user's profile Send private message 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-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.