我试图在汇编中创建完全随机的数字,但是每次启动程序它都会给我相同的数字,按相同的顺序。
如果数字是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 di, ax
mul bx
add si, ax
pop ax
mul cx
add si, ax
; Do addition
add di, 3039h
adc si, 0
; Save seed
mov [RNG_Seed], di
; Get result and mask bits
mov ax, si
and ah, 07Fh
pop di
pop si
pop cx
pop bx
ret
endp GenerateRandNum
我该怎么做才能在每次运行时获得不同的随机数?