【发布时间】:2016-11-19 21:52:39
【问题描述】:
我正在使用程序集 8086emu,我需要一个用于 8 个数字的数字生成器。
我尝试使用@johnfound 的这段代码:
RANDGEN: ; generate a rand no using the system time
RANDSTART:
MOV AH, 00h ; interrupts to get system time
INT 1AH ; CX:DX now hold number of clock ticks since midnight
mov ax, dx
xor dx, dx
mov cx, 10
div cx ; here dx contains the remainder of the division - from 0 to 9
add dl, '0' ; to ascii from '0' to '9'
mov ah, 2h ; call interrupt to display a value in DL
int 21h
RET
但仅在生成一个数字时才有用。重复调用得到相同的数字,因为该时钟每秒只滴答 18.2 次。
我尝试创建伪随机函数,但我对汇编还很陌生,但没有成功。
我想知道是否有办法在emu8086中做类似于java的Math.random()函数。
【问题讨论】:
-
尝试实现一个xorshift 随机数生成器。这应该非常简单和有用。
-
另外,Random number in assembly 有一个很长的详细答案,使用不同的 LCG,可能比这个更好的参数。
标签: assembly random x86 x86-16 emu8086