Sunday, August 29, 2010

16 bit xorshift rng in intel assembly

As described in George Marsaglia's paper located here. Marsaglia doesn't look at 8 or 16 bit, but there's more information here from cjh.

After some runs through diehard, these triplets were the only ones to not fail spectacularly:

  • 4,3,7
  • 5,11,6
  • 5,9,8

I didn't have an assembler handy, debug will do:

1791:0200 51 PUSH CX
1791:0201 52 PUSH DX
1791:0202 B80100 MOV AX,0001
1791:0205 89C2 MOV DX,AX
1791:0207 B103 MOV CL,03
1791:0209 D3E0 SHL AX,CL
1791:020B 31C2 XOR DX,AX
1791:020D 89D0 MOV AX,DX
1791:020F B105 MOV CL,05
1791:0211 D3E8 SHR AX,CL
1791:0213 31C2 XOR DX,AX
1791:0215 89D0 MOV AX,DX
1791:0217 B10B MOV CL,0B
1791:0219 D3E0 SHL AX,CL
1791:021B 31C2 XOR DX,AX
1791:021D 92 XCHG DX,AX
1791:021E 2E CS:
1791:021F A30302 MOV [0203],AX
1791:0222 5A POP DX
1791:0223 59 POP CX
1791:0224 C3 RET

No comments: