assembly - 如何检查文件是否已打开?
问题描述
我自己编写了以下代码:
#===========================================
# OpenFile - opens a file for reading
# arguments:
# $a0 - file name
# return:
# $v0 - file's descriptop/pointer
#-------------------------------------------
OpenFile:
# backup return address
addiu $sp, $sp, -12 # create space for 3 words
# (4*3=12 bytes) on the stack
# (push) for $ra
sw $ra, 0($sp) # backup return address $ra
# protect arguments from change
sw $a1, 4($sp) # protect string address
sw $a2, 8($sp) # protect char
# actual file open code
li $a1, 0 # Open for reading
li $a2, 0
li $v0, 13 # system call for open file
syscall # open a file (file descriptor returned in $v0)
# restore registers
lw $ra, 0($sp) # restore $ra
lw $a1, 4($sp) # load address counter
lw $a2, 8($sp) # load char to be replaced
# restore stack pointer
addiu $sp, $sp, 12 # return the space on the stack(pop)
# return
jr $ra
#===========================================
如何检查文件是否正确打开?
我应该检查中的非零内容$v0
吗?
解决方案
推荐阅读
- java - 使用作为参数给出的比较器对对象列表进行排序的类方法(Java)
- c# - 无法访问客户端应用程序
- sql - 如果 ID 存在于另一个表中,则插入行
- nginx - 如何在 Nginx 上配置具有相同 URL 的多个站点
- reactjs - 将事件处理程序放在 NextJS _document 中——以及 NextJS 页面和 React SPA 之间的关系
- apache-flink - 如何在 Apache Flink 中创建外部目录表
- c++ - CUDA: Fill matrix with results of summation
- java - 获取用户输入,然后使用 AWT 打印新文本
- javascript - How to fix get request and response with whole html
- symfony - 定义“nelmio_cors”不支持配置键“defaults”