为什么文件不可用不会给$ v0赋予负值?

时间:2019-05-12 01:01:40

标签: assembly file-io bitmap mips

#only 24-bits 600x50 pixels BMP files are supported
.eqv BMP_FILE_SIZE 90122
.eqv BYTES_PER_ROW 1800

.data
#space for the 600x50px 24-bits bmp image
.align 4
res:    .space 2
image:  .space BMP_FILE_SIZE

fname:  .asciiz "source1.bmp"

.text
#====================================================
# main - main program
#----------------------------------------------------
main:
    ## read bitmap file into 'image'
    jal read_bmp

exit:   
    li  $v0,10      #Terminate the program
    syscall
#=====================================================

read_bmp:
    #push $ra to the stack
    sub $sp, $sp, 4     
    sw  $ra, 4($sp)
    #push $s1  to the stack
    sub $sp, $sp, 4     
    sw  $s1, 4($sp)

    # open file for reading
    li $v0, 13
        la $a0, fname   #file name 
        li $a1, 0       #0 - open for reading
        li $a2, 0       #0 - ignore length ($a2 = the length of bytes to read)
        syscall
    move $s1, $v0       # save the file descriptor

    lw $s1, 4($sp)      #restore (pop) $s1
    add $sp, $sp, 4
    lw $ra, 4($sp)      #restore (pop) $ra
    add $sp, $sp, 4

    jr $ra

首先,目录中没有名为 source1.bmp 的文件。因此,根据this thread

  

enter image description here

该程序应将负值加载到 $v0 中。

但是,我的输出如下:

enter image description here

这是怎么回事?

然后如何/应该进行错误检查?

0 个答案:

没有答案