News:

Masm32 SDK description, downloads and other helpful links
Message to All Guests
NB: Posting URL's See here: Posted URL Change

Main Menu

Function to create random strings

Started by Vortex, October 29, 2020, 07:20:20 AM

Previous topic - Next topic

Biterider

Hi LiaoMi
My best guess is that UASM currently only supports 32-bit arithmetic for macro calculations.
In your case you are doing 64-bit calculations. The error messages are misleading...

Biterider

HSE

Hi LiaoMi!!

Are you sure that "sar" is valid directive for preprocessor?

It's not for ML64.

HSE
Equations in Assembly: SmplMath

Biterider

Hi
HSE is right.  :cool:

The following code works for me.
I added a seed value (initial state), so that on each run it generates a different value.


PCG32_STATE = @CatStr(@SubStr(%@Time, 1, 2), @SubStr(%@Time, 4, 2), @SubStr(%@Time, 7, 2))

__randa macro
  local r, t, x

  PCG32_STATE = PCG32_STATE * 6364136223846793005 + 0xda3e39cb94b95bdb

  t = PCG32_STATE
  r = ( ( ( t shr 18 ) xor t ) shr 27 )
;  r = ( ( ( t sar 18 ) xor t ) sar 27 )
  x = t shr 59
  t = r shr x
  r = r shl ( -x and 31 )
  r = r or t
  r = r and 0x7F

  exitm <r>
endm

__randc macro
  local a
 
  a = __randa()
  while a gt 'z' or \
    a lt '0' or \
    a ge ':' and a le '>' or \
    a ge '[' and a le '`' and a ne '_'
    a = __randa()
  endm

  exitm <a>
endm

__rands macro n
  local string

  .data
  string label byte
  repeat n
    db __randc()
  endm
  db 0
  .code
  exitm <string>
endm



Note: it appears that the calculations are performed using 64 bits, but that is not the case. The values are truncated internally to 32 bits!

Biterider

LiaoMi

Hi Biterider,
Hi HSE,

thanks, it works  :thup:

QuoteHi LiaoMi
Note: it appears that the calculations are performed using 64 bits, but that is not the case. The values are truncated internally to 32 bits!
Biterider

Is this also the case in the 64 bit version of Masm?