I am new to assembly, and I am having problems generating random numbers.
My code is simple: it generates 100 numbers in the 0-25
range and stores them in an array.
The problem I am experiencing is that when I run the con on the emu8086
assembler it runs successfully and generates 100 random numbers, that are stored in the array. But when I run it on the masm611
, it generates a new random number every 4 cycles. Which means the values in the array are consecutive same number for 4 values and then next random value is stored.
Here is my code:
.model small
.stack 100h
.data
range db 25
arr db 15 dup(0) ; an array
.code
mov ax,@data
mov ds,ax
mov cx,100 ;loop 100 times to get 100 random numbers
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
loop L1
mov ah,4ch ;returning control
int 21h
end
Is there is a problem in my code? Do I need to add something? Thanks.
Aucun commentaire:
Enregistrer un commentaire