我刚接触汇编语言,但是在生成随机数方面遇到了问题。
我的代码很简单:它生成100个在0-25
范围内的数字,并将它们存储在一个数组中。
我遇到的问题是,当我在emu8086
汇编器上运行时,它能够成功地生成100个随机数,并将它们存储在数组中。但是当我在masm611
汇编器上运行时,它每4个周期就会生成一个新的随机数。这意味着数组中的值连续出现4次相同的数字,然后才存储下一个随机数。
以下是我的代码:
.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
我的代码有问题吗?我需要添加些什么吗?谢谢。