Table of Contents

SPIM System Call

example

    li  $v0, 1           # service 1 is print integer
    add $a0, $t0, $zero  # load desired value into argument register $a0, using pseudo-op
    syscall

Table of Available Services

<html> <table border=1>

<tr>  <th>Service</th>  <th>Code in $v0</th>  <th>Arguments</th>  <th>Result</th>  </tr>
<tr><td>print integer</td>                 <td align="center">1</td>   <td>$a0 = integer to print</td>  <td>&nbsp;</td></tr>
<tr><td>print float</td>                   <td align="center">2</td>   <td>$f12 = float to print</td>   <td>&nbsp;</td></tr>
<tr><td>print double</td>                  <td align="center">3</td>   <td>$f12 = double to print</td>  <td>&nbsp;</td></tr>
<tr><td>print string</td>                  <td align="center">4</td>   <td>$a0 = address of null-terminated string to print</td>  <td>&nbsp;</td></tr>
<tr><td>read integer</td>                  <td align="center">5</td>   <td>&nbsp;</td>  <td>$v0 contains integer read</td></tr>
<tr><td>read float</td>                    <td align="center">6</td>   <td>&nbsp;</td>  <td>$f0 contains float read</td></tr>
<tr><td>read double</td>                   <td align="center">7</td>   <td>&nbsp;</td>  <td>$f0 contains double read</td></tr>
<tr><td>read string</td>                   <td align="center">8</td>   <td>$a0 = address of input buffer<br>$a1 = maximum number of characters to read</td>  <td><i>See note below table</i></td></tr>
<tr><td>sbrk (allocate heap memory)</td>   <td align="center">9</td>   <td>$a0 = number of bytes to allocate</td>  <td>$v0 contains address of allocated memory</td></tr>
<tr><td>exit (terminate execution)</td>   <td align="center">10</td>   <td>&nbsp;</td>  <td>&nbsp;</td></tr>
<tr><td>print character</td>              <td align="center">11</td>   <td>$a0 = character to print</td>  <td><i>See note below table</i></td></tr>
<tr><td>read character</td>               <td align="center">12</td>   <td>&nbsp;</td>  <td>$v0 contains character read</td></tr>
<tr><td>open file</td>                    <td align="center">13</td>   <td>$a0 = address of null-terminated string containing filename<br>$a1 = flags<br>$a2 = mode</td>  <td>$v0 contains file descriptor (negative if error).  <i>See note below table</i></td></tr>
<tr><td>read from file</td>               <td align="center">14</td>   <td>$a0 = file descriptor<br>$a1 = address of input buffer<br>$a2 = maximum number of characters to read</td>  <td>$v0 contains number of characters read (0 if end-of-file, negative if error).  <i>See note below table</i></td></tr>
<tr><td>write to file</td>                <td align="center">15</td>   <td>$a0 = file descriptor<br>$a1 = address of output buffer<br>$a2 = number of characters to write</td>  <td>$v0 contains number of characters written (negative if error).  <i>See note below table</i></td></tr>
<tr><td>close file</td>                   <td align="center">16</td>   <td>$a0 = file descriptor</td>  <td>&nbsp;</td></tr>
<tr><td>exit2 (terminate with value)</td> <td align="center">17</td>   <td>$a0 = termination result</td>  <td><i>See note below table</i></td></tr>
<tr><td align="center" colspan=4><em>Services 1 through 17 are compatible with the SPIM simulator, other than Open File (13) as described in the Notes below the table.
Services 30 and higher are exclusive to MARS.</em></td></tr>
<tr><td>time (system time)</td>           <td align="center">30</td>   <td>&nbsp;</td><td>$a0 = low order 32 bits of system time<br>$a1 = high order 32 bits of system time.  <i>See note below table</i></td></tr>
<tr><td>MIDI out</td>                     <td align="center">31</td>   <td>$a0 = pitch (0-127)<br>$a1 = duration in milliseconds<br>$a2 = instrument (0-127)<br>$a3 = volume (0-127)</td>  <td>Generate tone and return immediately.  <i>See note below table</i></td></tr>
<tr><td>sleep</td>                        <td align="center">32</td>   <td>$a0 = the length of time to sleep in milliseconds.</td>  <td>Causes the MARS Java thread to sleep for (at least) the specified number of milliseconds. This timing will not be precise, as the Java implementation will add some overhead.</td></tr>
<tr><td>MIDI out synchronous              <td align="center">33</td>   <td>$a0 = pitch (0-127)<br>$a1 = duration in milliseconds<br>$a2 = instrument (0-127)<br>$a3 = volume (0-127)</td>  <td>Generate tone and return upon tone completion.  <i>See note below table</i></td></tr>
<tr><td>print integer in hexadecimal</td> <td align="center">34</td>   <td>$a0 = integer to print</td>  <td>Displayed value is 8 hexadecimal digits, left-padding with zeroes if necessary.</td></tr>
<tr><td>print integer in binary</td>      <td align="center">35</td>   <td>$a0 = integer to print</td>  <td>Displayed value is 32 bits, left-padding with zeroes if necessary.</td></tr>
<tr><td>print integer as unsigned</td>    <td align="center">36</td>   <td>$a0 = integer to print</td>  <td>Displayed as unsigned decimal value.</td></tr>
<tr><td align="center">(not used)</td>    <td align="center">37-39</td><td>&nbsp;</td>  <td>&nbsp;</td></tr>
<tr><td>set seed</td>                     <td align="center">40</td>   <td>$a0 = i.d. of pseudorandom number generator (any int).<br>$a1 = seed for corresponding pseudorandom number generator.</td>  <td>No values are returned. Sets the seed of the corresponding underlying Java pseudorandom number generator (<tt>java.util.Random</tt>). <i>See note below table</i></td></tr>
<tr><td>random int</td>                   <td align="center">41</td>   <td>$a0 = i.d. of pseudorandom number generator (any int).</td>  <td>$a0 contains the next pseudorandom, uniformly distributed int value from this random number generator's sequence. <i>See note below table</i></td></tr>
<tr><td>random int range</td>             <td align="center">42</td>   <td>$a0 = i.d. of pseudorandom number generator (any int).<br>$a1 = upper bound of range of returned values.</td>  <td>$a0 contains pseudorandom, uniformly distributed int value in the range 0 <= [int] < [upper bound], drawn from this random number generator's sequence.  <i>See note below table</i></td></tr>
<tr><td>random float</td>                 <td align="center">43</td>   <td>$a0 = i.d. of pseudorandom number generator (any int).</td>  <td>$f0 contains the next pseudorandom, uniformly distributed float value in the range 0.0 <= f < 1.0 from this random number generator's sequence.  <i>See note below table</i></td></tr>
<tr><td>random double</td>                <td align="center">44</td>   <td>$a0 = i.d. of pseudorandom number generator (any int).</td>  <td>$f0 contains the next pseudorandom, uniformly distributed double value in the range 0.0 <= f < 1.0 from this random number generator's sequence.  <i>See note below table</i></td></tr>
<tr><td align="center">(not used)</td>    <td align="center">45-49</td><td>&nbsp;</td>  <td>&nbsp;</td></tr>
<tr><td>ConfirmDialog</td>                <td align="center">50</td>   <td>$a0 = address of null-terminated string that is the message to user</td>  <td>$a0 contains value of user-chosen option<br>0: Yes<br>1: No<br>2: Cancel</td></tr>
<tr><td>InputDialogInt</td>               <td align="center">51</td>   <td>$a0 = address of null-terminated string that is the message to user</td>  <td>$a0 contains int read<br>$a1 contains status value<br>0: OK status<br>-1: input data cannot be correctly parsed<br>-2: Cancel was chosen<br>-3: OK was chosen but no data had been input into field</td></tr>
<tr><td>InputDialogFloat</td>             <td align="center">52</td>   <td>$a0 = address of null-terminated string that is the message to user</td>  <td>$f0 contains float read<br>$a1 contains status value<br>0: OK status<br>-1: input data cannot be correctly parsed<br>-2: Cancel was chosen<br>-3: OK was chosen but no data had been input into field</td></tr>
<tr><td>InputDialogDouble</td>            <td align="center">53</td>   <td>$a0 = address of null-terminated string that is the message to user</td>  <td>$f0 contains double read<br>$a1 contains status value<br>0: OK status<br>-1: input data cannot be correctly parsed<br>-2: Cancel was chosen<br>-3: OK was chosen but no data had been input into field</td></tr>
<tr><td>InputDialogString</td>            <td align="center">54</td>   <td>$a0 = address of null-terminated string that is the message to user<br>$a1 = address of input buffer<br>$a2 = maximum number of characters to read</td>  <td><i>See Service 8 note below table</i><br>$a1 contains status value<br>0: OK status. Buffer contains the input string.<br>-2: Cancel was chosen. No change to buffer. <br>-3: OK was chosen but no data had been input into field. No change to buffer.<br>-4: length of the input string exceeded the specified maximum. Buffer contains the maximum allowable input string plus a terminating null.</td></tr>
<tr><td>MessageDialog</td>                <td align="center">55</td>   <td>$a0 = address of null-terminated string that is the message to user<br>$a1 = the type of message to be displayed:<br> 

0: error message, indicated by Error icon <!– <img src=“SyscallMessageDialogError.gif”> –> <br> 1: information message, indicated by Information icon <!– <img src=“SyscallMessageDialogInformation.gif”> –> <br> 2: warning message, indicated by Warning icon <!– <img src=“SyscallMessageDialogWarning.gif”> –> <br> 3: question message, indicated by Question icon <!– <img src=“SyscallMessageDialogQuestion.gif”> –> <br> other: plain message (no icon displayed) </td> <td>N/A</td></tr>

<tr><td>MessageDialogInt</td>             <td align="center">56</td>   <td>$a0 = address of null-terminated string that is an information-type message to user<br>$a1 = int value to display in string form after the first string</td>  <td>N/A</td></tr>
<tr><td>MessageDialogFloat</td>           <td align="center">57</td>   <td>$a0 = address of null-terminated string that is an information-type message to user<br>$f12 = float value to display in string form after the first string</td>  <td>N/A</td></tr>
<tr><td>MessageDialogDouble</td>          <td align="center">58</td>   <td>$a0 = address of null-terminated string that is an information-type message to user<br>$f12 = double value to display in string form after the first string</td>  <td>N/A</td></tr>
<tr><td>MessageDialogString</td>          <td align="center">59</td>   <td>$a0 = address of null-terminated string that is an information-type message to user<br>$a1 = address of null-terminated string to display after the first string</td>  <td>N/A</td></tr>

</table> </html>