li $v0, 1 # service 1 is print integer move $a0, $t0 # load desired value into argument register $a0, using pseudo-op syscall
Service | Code in $v0 | Arguments | Result |
---|---|---|---|
print integer | 1 | $a0 = integer to print | |
print float | 2 | $f12 = float to print | |
print double | 3 | $f12 = double to print | |
print string | 4 | $a0 = address of null-terminated string to print | |
read integer | 5 | $v0 contains integer read | |
read float | 6 | $f0 contains float read | |
read double | 7 | $f0 contains double read | |
read string | 8 | $a0 = address of input buffer $a1 = maximum number of characters to read | |
sbrk (allocate heap memory) | 9 | $a0 = number of bytes to allocate | $v0 contains address of allocated memory |
exit (terminate execution) | 10 | ||
print character | 11 | $a0 = character to print | |
read character | 12 | $a0 contains character read | |
open file | 13 | $a0 = address of null-terminated string containing filename $a1 = flags $a2 = mode | $a0 contains file descriptor |
read from file | 14 | $a0 = file descriptor $a1 = address of input buffer $a2 = maximum number of characters to read | $a0 contains number of characters read |
write to file | 15 | $a0 = file descriptor $a1 = address of output buffer $a2 = number of characters to write | $a0 contains number of characters written |
close file | 16 | $a0 = file descriptor | |
exit2 (terminate with value) | 17 | $a0 = termination result |
# Sample MIPS program that writes to a new file. # by Kenneth Vollmar and Pete Sanderson .data fout: .asciiz "testout.txt" # filename for output buffer: .asciiz "The quick brown fox jumps over the lazy dog." .text ############################################################### # Open (for writing) a file that does not exist li $v0, 13 # system call for open file la $a0, fout # output file name li $a1, 0 # flags li $a2, 1 # Open for writing (mode is 0: read, 1: write) syscall # open a file (file descriptor returned in $a0) ############################################################### # Write to file just opened move $s6, $a0 # save the fd (syscall below will overwrite $a0) li $v0, 15 # system call for write to file la $a1, buffer # address of buffer from which to write li $a2, 44 # hardcoded buffer length syscall # write to file ############################################################### # Close the file li $v0, 16 # system call for close file move $a0, $s6 # Restore fd syscall # close file ###############################################################