I am a complete beginner in MIPS and I am trying to understand a piece of code which is about opening a file , saving the file and then closing the file.
#open file
li $v0, 13
la $a0, fname #file name
li $a1, 1 #flags: 1-write file
li $a2, 0 #mode: ignored
syscall
move $s1, $v0 # save the file descriptor
#check for errors - if the file was opened
#...
#save file
li $v0, 15
move $a0, $s1
la $a1, image
li $a2, BMP_FILE_SIZE
syscall
#close file
li $v0, 16
move $a0, $s1
syscall
I understand everything except this 'saving the file descriptor part'. Can anybody explain what a file descriptor is and why we are using it here? The instructions that I don't understand :
- move $s1, $v0
- move $a0, $s1
- move $a0, $s1