将小写文件从大写转换为另一个文件

时间:2019-04-18 20:19:35

标签: mips mars-simulator

我是一名正在学习mips的学生,我有一个问题如下:

从文件中取出所有小写字母,将它们转换为大写字母,然后将它们打印在另一个文件中。 我尝试打开第一个文件“ Alice”,这是我需要处理的文件,并将所有小写字母“取”,将它们转换为大写,然后写入另一个名为“ AliceU”的文件,因此,在我的代码中,我打开了2个文件,阅读了第一个文件,并尝试写入另一个文件,但是我认为有些错误,因此我要求您在我的代码中可能会注意到不正确的实用信息

.data
filename: .asciiz "Allice.txt"
filename2: .asciiz "AlliceU.txt"
input: .space 1024

.text
# Open (for reading)
  li   $v0, 13              # system call for open file
  la   $a0, filename        # output file name
  li   $a1, 0               # Open for writing (flags are 0: read, 1: write)
  move $s0, $v0             # save the file descriptor 
  syscall                   # open a file (file descriptor returned in $v0)

ReadFile:
li   $v0, 14        # system call for reading from file
move $a0, $s0       # file descriptor 
la   $a1, input    # address of buffer from which to read
li   $a2, 1024       # hardcoded buffer length
syscall             # read from file

# Open (for writing)
  li   $v0, 13              # system call for open file
  la   $a0, filename2       # output file name
  li   $a1, 1               # Open for writing (flags are 0: read, 1: write)
  move $s1, $v0             # save the file descriptor 
  syscall                   # open a file (file descriptor returned in $v0)


Replace:
    lb $t1, input($t3)
    beq $t1, 0, exit
    blt $t1, 'a', case
    bgt $t1, 'z', case
    sub $t1, $t1, 32
    sb $t1, input($t3)

case: 
    addi $t3, $t3, 1
    j Replace

WriteFile:
# Write to file
li $v0,15
move $a0,$s1
la $a1,input
la $a2,1024
syscall

exit:
# Close the file 
  li   $v0, 16       # system call for close file
  move $a0, $s1      # file descriptor to close
  syscall            # close file
  li   $v0, 16       # system call for close file
  move $a0, $s0      # file descriptor to close
  syscall            # close file

因此,我从之前在这里提出的问题中获取了一些建议,但我无法完全理解这件事是如何工作的。

0 个答案:

没有答案