Author Topic: Function to create random strings  (Read 5227 times)

Biterider

  • Member
  • *****
  • Posts: 1082
  • ObjAsm Developer
    • ObjAsm
Re: Function to create random strings
« Reply #15 on: August 05, 2022, 06:56:26 AM »
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

  • Member
  • *****
  • Posts: 2497
  • AMD 7-32 / i3 10-64
Re: Function to create random strings
« Reply #16 on: August 05, 2022, 08:23:44 AM »
Hi LiaoMi!!

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

It's not for ML64.

HSE
Equations in Assembly: SmplMath

Biterider

  • Member
  • *****
  • Posts: 1082
  • ObjAsm Developer
    • ObjAsm
Re: Function to create random strings
« Reply #17 on: August 06, 2022, 08:48:00 PM »
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.

Code: [Select]
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

  • Member
  • *****
  • Posts: 1055
Re: Function to create random strings
« Reply #18 on: August 22, 2022, 04:46:48 AM »
Hi Biterider,
Hi HSE,

thanks, it works  :thup:

Quote
Hi 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?