MIPS汇编语言SYSCALL指令的用法

来源:互联网 发布:共享文件输入网络凭据 编辑:程序博客网 时间:2024/04/29 07:18

SYSCALL functions available in MARS

Introduction

A number of system services, mainly for input and output, are available for use by your MIPS program. They are described in the table below.

MIPS register contents are not affected by a system call, except for result registers as specified in the table below.

How to use SYSCALL system services

Step 1. Load the service number in register $v0.
Step 2. Load argument values, if any, in $a0, $a1, $a2, or $f12 as specified.
Step 3. Issue the SYSCALL instruction.
Step 4. Retrieve return values, if any, from result registers as specified.

Example: display the value stored in $t0 on the console
    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

ServiceCode in $v0ArgumentsResultprint integer1$a0 = integer to print print float2$f12 = float to print print double3$f12 = double to print print string4$a0 = address of null-terminated string to print read integer5 $v0 contains integer readread float6 $f0 contains float readread double7 $f0 contains double readread string8$a0 = address of input buffer
$a1 = maximum number of characters to readSee note below tablesbrk (allocate heap memory)9$a0 = number of bytes to allocate$v0 contains address of allocated memoryexit (terminate execution)10  print character11$a0 = character to printSee note below tableread character12 $v0 contains character readopen file13$a0 = address of null-terminated string containing filename
$a1 = flags
$a2 = mode$v0 contains file descriptor (negative if error). See note below tableread from file14$a0 = file descriptor
$a1 = address of input buffer
$a2 = maximum number of characters to read$v0 contains number of characters read (0 if end-of-file, negative if error). See note below tablewrite to file15$a0 = file descriptor
$a1 = address of output buffer
$a2 = number of characters to write$v0 contains number of characters written (negative if error). See note below tableclose file16$a0 = file descriptor exit2 (terminate with value)17$a0 = termination resultSee note below tableServices 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.time (system time)30 $a0 = low order 32 bits of system time
$a1 = high order 32 bits of system time. See note below tableMIDI out31$a0 = pitch (0-127)
$a1 = duration in milliseconds
$a2 = instrument (0-127)
$a3 = volume (0-127)Generate tone and return immediately. See note below tablesleep32$a0 = the length of time to sleep in milliseconds.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.MIDI out synchronous33$a0 = pitch (0-127)
$a1 = duration in milliseconds
$a2 = instrument (0-127)
$a3 = volume (0-127)Generate tone and return upon tone completion. See note below tableprint integer in hexadecimal34$a0 = integer to printDisplayed value is 8 hexadecimal digits, left-padding with zeroes if necessary.print integer in binary35$a0 = integer to printDisplayed value is 32 bits, left-padding with zeroes if necessary.print integer as unsigned36$a0 = integer to printDisplayed as unsigned decimal value.(not used)37-39  set seed40$a0 = i.d. of pseudorandom number generator (any int).
$a1 = seed for corresponding pseudorandom number generator.No values are returned. Sets the seed of the corresponding underlying Java pseudorandom number generator (java.util.Random). See note below tablerandom int41$a0 = i.d. of pseudorandom number generator (any int).$a0 contains the next pseudorandom, uniformly distributed int value from this random number generator's sequence.See note below tablerandom int range42$a0 = i.d. of pseudorandom number generator (any int).
$a1 = upper bound of range of returned values.$a0 contains pseudorandom, uniformly distributed int value in the range 0 <= [int] < [upper bound], drawn from this random number generator's sequence. See note below tablerandom float43$a0 = i.d. of pseudorandom number generator (any int).$f0 contains the next pseudorandom, uniformly distributed float value in the range 0.0 <= f < 1.0 from this random number generator's sequence. See note below tablerandom double44$a0 = i.d. of pseudorandom number generator (any int).$f0 contains the next pseudorandom, uniformly distributed double value in the range 0.0 <= f < 1.0 from this random number generator's sequence. See note below table(not used)45-49  ConfirmDialog50$a0 = address of null-terminated string that is the message to user$a0 contains value of user-chosen option
0: Yes
1: No
2: CancelInputDialogInt51$a0 = address of null-terminated string that is the message to user$a0 contains int read
$a1 contains status value
0: OK status
-1: input data cannot be correctly parsed
-2: Cancel was chosen
-3: OK was chosen but no data had been input into fieldInputDialogFloat52$a0 = address of null-terminated string that is the message to user$f0 contains float read
$a1 contains status value
0: OK status
-1: input data cannot be correctly parsed
-2: Cancel was chosen
-3: OK was chosen but no data had been input into fieldInputDialogDouble53$a0 = address of null-terminated string that is the message to user$f0 contains double read
$a1 contains status value
0: OK status
-1: input data cannot be correctly parsed
-2: Cancel was chosen
-3: OK was chosen but no data had been input into fieldInputDialogString54$a0 = address of null-terminated string that is the message to user
$a1 = address of input buffer
$a2 = maximum number of characters to readSee Service 8 note below table
$a1 contains status value
0: OK status. Buffer contains the input string.
-2: Cancel was chosen. No change to buffer. 
-3: OK was chosen but no data had been input into field. No change to buffer.
-4: length of the input string exceeded the specified maximum. Buffer contains the maximum allowable input string plus a terminating null.MessageDialog55$a0 = address of null-terminated string that is the message to user
$a1 = the type of message to be displayed:
0: error message, indicated by Error icon
0 0
原创粉丝点击