MIPS中$ a1 = flag和$ a2 =模式寄存器的含义

时间:2016-10-25 17:26:32

标签: file mips cpu-registers

我不明白$ a1和$ a2正在做什么。在本书http://spimsimulator.sourceforge.net/HP_AppA.pdf中,没有描述$ a1或$ a2中的1或0应该是什么意思。只有: $ a0 =文件名(字符串),$ a1 = flags,$ a2 = mode。 哪个标志和什么模式?没有解释。 例如,在此代码中:

#write on file
#open
li $v0, 13      # system call for open file
la $a0, fout    # load address of output file
li $a1, 1       # Open for reading
li $a2, 0       
syscall         # open a file (file descriptor returned in $v0)
move $s6, $v0   # save the file descriptor 

#write
li $v0, 15      # system call for write to file
move $a0, $s6   # file descriptor 
la $a1, buffer  # address of buffer which to write
li $a2, 30      # buffer length
syscall         # write to file

#close
li $v0, 16      # system call for close file
move $a0, $s6   # file descriptor to close
syscall         # close file

1 个答案:

答案 0 :(得分:0)

我不知道这是否记录在SPIM的任何地方(源代码除外),但对于MARS,以下情况应该是真的:

flags: 0 = read-only
       1 = write-only with create
       9 = write-only with create and append

mode: Ignored.

修改:我选中了SPIM's source code,它似乎只是$a1$a2点击flagsmodeopen