flat assembler
Message board for the users of flat assembler.

Index > Macroinstructions > Is it possible to shuffle definitions?

Author
Thread Post new topic Reply to topic
thetrick



Joined: 19 Feb 2020
Posts: 18
thetrick 17 Aug 2021, 20:12
Hello everyone.

I'd want to know if it's possible to shuffle definitions. For example i have the following code:

Code:
mov REG1, REG2
lea REG2, [REG3 + 0x10]    


I need to replace REG1, REG2, REG3 with random registers (without repeating) so i need a macro which assigns the registers to REG1, REG2, REG3. For example:

REG1 replaces to eax
REG2 replaces to ebx
REG3 replaces to ecx

The main goal is htey shouldn't repeat.

Thank in advance.
Post 17 Aug 2021, 20:12
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4060
Location: vpcmpistri
bitRAKE 17 Aug 2021, 20:22
[fasmg] Maybe something like:
Code:
struc PRNG val*

        ; your favorite prng function goes here

        . = rnd mod val
end struc

myRnd PRNG 6 ; need to get a random number in range [0-5]
iterate <REG1,REG2,REG3>,\
        eax,ebx,ecx,\
        eax,ecx,ebx,\
        ebx,eax,ecx,\
        ebx,ecx,eax,\
        ecx,eax,ebx,\
        ecx,ebx,eax

        indx myRnd+1
        mov REG1, REG2
        lea REG2, [REG3 + 0x10]
        break
end iterate    
... a more general approach is certainly possible. Instead of using a table: get a random number in range [0,N!) and then calculate the factoradic (the digits are the indices in the Array[N] of possible values).
Post 17 Aug 2021, 20:22
View user's profile Send private message Visit poster's website Reply with quote
macomics



Joined: 26 Jan 2021
Posts: 1004
Location: Russia
macomics 18 Aug 2021, 15:09
Quote:

I need to replace REG1, REG2, REG3 with random registers (without repeating) so i need a macro which assigns the registers to REG1, REG2, REG3. For example:

REG1 replaces to eax
REG2 replaces to ebx
REG3 replaces to ecx

What's wrong with that?
Code:
macro name REG1, REG2, REG3 { mov REG1, REG2
 lea REG2, [REG3 + 0x10] }    
Just list them in the right order. Or do you want it to work in runtime as well?
Code:
list1 equ eax,ebx,ecx
list2 equ ebx,ecx,eax
...
macro name_call index {name list#index}    
Post 18 Aug 2021, 15:09
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.