Assembly random number generation

I am new to assembly and am having trouble generating random numbers.

My code is simple: it generates 100 numbers in a range 0-25and stores them in an array.

The problem I'm experiencing is that when running con in assembler, emu8086it starts up successfully and generates 100 random numbers that are stored in the array. But when I run it on masm611, it generates a new random number every 4 cycles. This means that the values ​​in the array have the same serial number for 4 values, and then the next random value is written.

Here is my code:

.model small
.stack 100h
.data

range db 25
i db 0                  ;iterator

arr db 15 dup(0)        ; an array

.code
   mov ax,@data
   mov ds,ax

   mov bx,offset arr    ;getting the adress of the arr in bx
    L1:

    mov ah,2ch      
    int 21h

    mov ah,0  
    mov al,dl            ;using dl by seeing  2ch details
    div range            ; so the number is in range


    mov [bx],ah          ;ah has remainder as using 8 bits div and  
    inc bx               ;moving to the next index

    inc i
    cmp i,100
    jbe L1


mov ah,4ch               ;returning control
int 21h 
end

Is there a problem in my code? Do I need to add something? Thank.

+4
2

, . . , .

, , - "", .

.

, , , ( ) - () .

( ) , . wikipedia.

, , , . -. AX 4 :

; here ax contains the previous number

    mul ax
    mov al, ah
    mov ah, dl 

; here ax contains the next pseudo random number.
+6

johnfound, , , . RNG, 4 2017 .

:

    mul ax      ; square random number
    add cx, bx  ; calculate next iteration of Weyl sequence
    add ax, cx  ; add Weyl sequence
    mov al, ah  ; get lower byte of random number from higher byte of ax
    mov ah, dl  ; get higher byte of random number from lower byte of dx
    ...         ; use new random number stored in ax

:

  • ax.
  • bx ( , , -, ). 8 .
  • cx bx .

, 0 . , , .

+1

All Articles