flat assembler
Message board for the users of flat assembler.
 Home   FAQ   Search   Register 
 Profile   Log in to check your private messages   Log in 
flat assembler > Macroinstructions > Need to place macro rand in struc & macro db,dw,dd, etc

Author
Thread Post new topic Reply to topic
ProMiNick



Joined: 24 Mar 2012
Posts: 48
Location: Russian Federation, Sochi
Need to place macro rand in struc & macro db,dw,dd, etc

Code:

UPPER_MASK = 80000000h ;MININT
LOWER_MASK = 7FFFFFFFh ;MAXINT

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

macro randinit i
{
  MT0i 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 1or (mag0*((Y+1and 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 1xor (mag0*((Y+1and 1)+mag1*(Y and 1)) \\}
     \}
     Y = MT623 and UPPER_MASK or MT0 and LOWER_MASK
     rept 1 MM1:396 \{ MT623 = MT\#MM1 xor (Y shr 1xor (mag0*((Y+1and 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 7and 9D2C5680h)
   Y = Y xor ((Y shl 15and 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.
Post 22 Sep 2016, 17:21
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 14848
Location: Lost in translation
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
}

Post 22 Sep 2016, 18:17
View user's profile Send private message Visit poster's website 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


Powered by phpBB © 2001-2005 phpBB Group.

Main index   Download   Documentation   Examples   Message board
Copyright © 2004-2016, Tomasz Grysztar.