SIPM模拟器 MIPS汇编语言实现读取文件

 语法不清楚参考https://blog.csdn.net/qq_40570410/article/details/106903645这篇博文。

执行时建立一个file.txt文件,路径和汇编代码的位置放在一起,可以直接放在桌面上使用

# Sample MIPS program that read a file. 

.data
fout:   .asciiz "file.txt"      #filename for read
buffer: .space 10				#sapce is 10

.text
	.globl main
main:
  # Open (for reading) a file
  li $v0, 13       				# system call for open file
  la $a0, fout     				# read file name
  li $a1, 0        				# flags
  syscall          				# open a file (file descriptor returned in $v0)

  move $t0, $v0    				# save file descriptor in $t0		
  
  # Read to file just opened  
  li $v0, 14       				# system call for read to file
  la $a1, buffer   				# address of buffer from which to write
  li $a2, 10       				# number of characters to write
  move $a0, $t0    				# put the file descriptor in $a0		
  syscall          				# write to file

  # Get the value from certain address
  la $a0, buffer 				#load the address into $a0

  li $v0, 4						# print the string out
  syscall  

  # Close the file 
  li $v0, 16       				# system call for close file
  move $a0, $t0    				# Restore containing
  syscall          				# close file

  li $v0, 10 					# end the file
  syscall 

 

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值