flat assembler
Message board for the users of flat assembler.

 Index > Macroinstructions > Need to place macro rand in struc & macro db,dw,dd, etc
Author
ProMiNick

Joined: 24 Mar 2012
Posts: 706
Location: Russian Federation, Sochi
ProMiNick 22 Sep 2016, 17:21
Code:
```UPPER_MASK = 80000000h ;MININT

; RAND.N=624,RAND.M=397

macro randinit i
{
MT0= i and 0FFFFFFFFh
TMP=(MT0 xor (MT0 shr 30))*1812433253+1
rept 624 K \{
MT\#K = TMP and 0FFFFFFFFh
TMP = (MT\#K xor (MT\#K shr 30))*1812433253+K+1
\}
MTi=0
}

macro rand
{  local mag0,mag1

mag0=0
mag1=9908B0dfh
if MTi >=624
if MTi = 625
randinit 5489
end if
rept 228 KK:0 \{ ;rept N-M+1
rept 1 KKP1:KK+1 \\{ Y = MT\#KK and UPPER_MASK or MT\\#KKP1 and LOWER_MASK \\}
rept 1 KKPM:KK+397 \\{ MT\#KK=MT\\#KKPM xor (Y shr 1) or (mag0*((Y+1) and 1)+mag1*(Y and 1)) \\}
\}
rept 396 KK:228 \{ ;rept M-1
rept 1 KKP1:KK+1 \\{ Y = MT\#KK and UPPER_MASK or MT\\#KKP1 and LOWER_MASK \\}
rept 1 KKPMMN:KK-227 \\{ MT\#KK=MT\\#KKPMMN or (Y shr 1) xor (mag0*((Y+1) and 1)+mag1*(Y and 1)) \\}
\}
rept 1 MM1:396 \{ MT623 = MT\#MM1 xor (Y shr 1) xor (mag0*((Y+1) and 1)+mag1*(Y and 1)) \}
MTi=0
end if
rept 625 K:0 \{
if K=MTi
Y = MT\#K
end if
\}
MTi=MTi+1
Y = Y xor (Y shr 11)
Y = Y xor ((Y shl 7) and 9D2C5680h)
Y = Y xor ((Y shl 15) and 0efc60000h)
Y = Y xor (Y shr 18)
}
```

Need:
Code:
```dd 'd',rand,7,rand ;launch rand macro and dd Y value, if launched first time do macro randinit with parameter %t too
somelabel dd rand ;launch rand macro and dd Y value
```

Is there any way to use random in expressions?

_________________
I don`t like to refer by "you" to one person.
My soul requires acronim "thou" instead.
22 Sep 2016, 17:21
revolution
When all else fails, read the source

Joined: 24 Aug 2004
Posts: 19096
revolution 22 Sep 2016, 18:17
You can override dd with a macro and a struc:

Assuming your rand macro returns the value in a variable named Y
Code:
```macro dd [stuff] {
local found_rand
forward
found_rand equ
match =rand,stuff \{
rand
dd Y
found_rand equ 1
\}
match ,found_rand \{
dd stuff
\}
}
struc dd [stuff] {
common
label . dword at \$
dd stuff
}    ```
22 Sep 2016, 18:17
 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