-1

arm 汇编代码中是否有任何特定程序接近生成 32 位二进制随机数?我需要一个程序的 1000 个测试用例。

4

1 回答 1

1

在此链接中是用于 PRNG( xorshift生成器)的 32 位 ARM 代码: http ://hackipedia.org/Platform/3D0/html,%203DO%20SDK%20Documentation/Type%20A/tktfldr/acbfldr/2acbh.html

基本算法为newbit:=bit33 EOR bit20,将33位数字左移放入newbit底部;对所有需要的新位(即 32 位)执行此操作。通过最大限度地利用 ARM 的桶形移位器,可以对整个操作进行紧凑的编码:

; enter with seed in R0 (32 bits), R1 (1 bit in least significant bit)
; R2 is used as a temporary register.
; on exit the new seed is in R0 and R1 as before
; Note that a seed of 0 will always produce a new seed of 0.
; All other values produce a maximal length sequence.
;
    TST    R1, R1, LSR #1                       ; top bit into Carry
    MOVS   R2, R0, RRX                          ; 33 bit rotate right
    ADC    R1, R1, R1                           ; carry into lsb of R1
    EOR    R2, R2, R0, LSL #12                  ; (involved!)
    EOR    R0, R2, R2, LSR #20                  ; (similarly involved!)

https://en.wikipedia.org/wiki/Pseudorandom_number_generator

于 2016-03-03T16:54:44.453 回答