how do i display element 98 at random position inside the array in mips using syscall 42

53 views Asked by At

the following is an array in mips

.byte

16,16,16,16,16,16,16,16,16,16,16

16,12,12,12,41,22,22,22,22,25,16

16,12,12,12,21,22,22,22,22,25,16

16,12,12,12,21,22,22,22,22,25,16

16,12,14,14,83,42,24,24,24,24,16

16,12,21,12,98,32,32,43,34,34,16

16,12,11,13,12,32,34,23,42,32,16

16,16,16,16,16,16,16,16,16,16,I6

I made mips code where when keyboard input is provided element 83 will move inside the array in any of 4 directions so when element 83 reaches element 98 . element 98 needs to be displayed again randomly in a new position inside the arIay. i did read through a stack overflow answer for generating random numbers but those were not exactly helpful as those generate random number and i want to generate element 98 in random position. i assumed the outterbounds where the total number of element in the array and t tried to write a code t=using syscall 42 but i was stuck in completing the code

#t0 is the array address

li $a0,98 la $a1,88 #outterbounds li $v0,42 syscall sb $a0,($t0) addi $t0,$t0,1 #increase array address

1

There are 1 answers

5
Jester On

Note that according to the documentation I found, the random number is returned in $a0 so you should not use that for your 98.

li $a0, some-random-id # for random generator
li $a1, 88             # upper limit
li $v0, 42             # syscall number
syscall                # get random in $a0
addu $a0, $a0, $t0     # add base address to $a0
li $t1, 98             # the value
sb $t1, ($a0)          # store