MIPS 32 程序:随机整数数组

问题描述

我正在尝试编写一个程序,该程序可以在数字 58 到 768 之间生成一个由 12 个随机整数组成的数组。我不知道如何修改它以使最小值为 58 并将其保存到一个数组中。它可以为 spacestr 生成整数,但我不知道如何让它转到数组并设置最小值。

.data
spacestr: .asciiz " "
array: .space 48

.text
# get the time
li $v0,30 # gets time in milliseconds
syscall

move $t0,$a0

# seed the random generator (just once)
li $a0,1 # random generator id
move $a1,$t0 # seed from time
li $v0,40 # seed random number generator syscall
syscall

# seeding done

# generate 12 random integers from the seeded generator
li $t2,13 # max number of iterations + 1
li $t3,0 # current iteration number

LOOP:
li $a0,1 # id is the same as random generator id
li $a1,768 # upper bound of range
li $v0,42 # random int range ???
syscall

# $a0 holds the random number

# loop terminating condition
addi $t3,$t3,1 # increment the number of iterations
beq $t3,$t2,EXIT # branch to EXIT if iterations is 12

#a0 still holds random number so print it
li $v0,1 # print integer syscall
syscall

# print a space
la $a0,spacestr # load the address of the string
li $v0,4 # print string syscall
syscall

# do another iteration
j LOOP

# exit program
EXIT:

li $v0,10 # exit syscall
syscall

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)