In: Computer Science
Provided code: .data arrayB: .word 0xffff, 0xffff, 0xffff, 0xffff .text
Using syscalls
o A “syscall” is a function that is provided by the operating system of the MIPS computer, not by the MIPS architecture itself. Examples are the ability to print data to the MIPS computer’s display monitor, obtain the time of day, etc.
o Open the MARS help screen, and select the Syscalls tab to bring up the available syscalls. Find and review the section “How to use SYSCALL system services.”
o You will use syscall 41, “random int.” Use of a syscall requires a series of MIPS instructions. You must provide the “setup” of a syscall by setting values in registers, then make the syscall itself.
Write a loop that will generate 6 random integers and store them in arrayB.
Write instructions to prepare for a future loop, including the following actions:
Write instructions to complete the body of the loop, including the following actions:
Answer:
Given that
provided code:
.data
arrayB:.word 0xffff,0xffff,0xffff,0xffff
.text
I have implemented Using "syscall" is a function that is provided by the operating system of the MIPS computer, not the MIPS architecture itself.
code:
.data
arrayB: .word 0:5
.text
la $a1, arrayB
loop:
bgt $t0,5,exit #check if greater than 6
li $v0, 41 #syscall for random int
syscall
mul $t1, $t0, 4 #multiply to calculate offset for array
addu $t2, $t1, $a1 #calculate offseted address
sw $a0, 0($t2) #store at offseted address
addi $t0,$t0,1 #increment loop counter
j loop #jump to label
exit:
Screenshot: