flat assembler
Message board for the users of flat assembler.

 Index > Macroinstructions > Is it possible to shuffle definitions?
Author
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.

17 Aug 2021, 20:12
bitRAKE

Joined: 21 Jul 2003
Posts: 3911
Location: vpcmipstrm
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).
17 Aug 2021, 20:22
macomics

Joined: 26 Jan 2021
Posts: 909
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}    ```
18 Aug 2021, 15:09
 Display posts from previous: All Posts1 Day7 Days2 Weeks1 Month3 Months6 Months1 Year Oldest FirstNewest First

 Jump to: Select a forum Official----------------AssemblyPeripheria General----------------MainTutorials and ExamplesDOSWindowsLinuxUnixMenuetOS Specific----------------MacroinstructionsOS ConstructionIDE DevelopmentProjects and IdeasNon-x86 architecturesHigh Level LanguagesProgramming Language DesignCompiler Internals Other----------------FeedbackHeapTest Area

Forum Rules:
 You cannot post new topics in this forumYou cannot reply to topics in this forumYou cannot edit your posts in this forumYou cannot delete your posts in this forumYou cannot vote in polls in this forumYou cannot attach files in this forumYou can download files in this forum