小编S. *_*osh的帖子

如何在汇编中播种随机数生成器?

我试图在汇编中创建一个完整的随机数,但每次启动程序时,它都会以相同的顺序给出相同的数字。如果数字是 12、132、4113 等,每次我启动代码时它都会重复它们。

我试图制作的程序有点像猜谜游戏。

    IDEAL
MODEL small
STACK 100h
DATASEG
;vars here
RNG_Seed dw ? 

CODESEG
; Generates a pseudo-random 15-bit number.
; Parameters: <none>
; Clobbers:   AX, DX
; Returns:    AX contains the random number
proc GenerateRandNum
   push bx
   push cx
   push si
   push di


   ; 32-bit multiplication in 16-bit mode (DX:AX * CX:BX == SI:DI)
   mov  ax, [RNG_Seed]
   xor  dx, dx
   mov  cx, 041C6h
   mov  bx, 04E6Dh
   xor  di, di
   push ax
   mul  bx
   mov  si, dx
   xchg …
Run Code Online (Sandbox Code Playgroud)

random x86 assembly x86-16

5
推荐指数
1
解决办法
2284
查看次数

标签 统计

assembly ×1

random ×1

x86 ×1

x86-16 ×1