【发布时间】:2016-10-20 03:51:53
【问题描述】:
.data
fnf: .ascii "The file was not found: "
###important: UPDATE THIS PATH TO WHERE YOU SAVED THE TEXT FILE
#asciiz directive creates null-terminated string
file: .asciiz "C:/Users/mmono/OneDrive/Documents/input.txt"
pstring:.asciiz " characters.\nFile contents:"
buffer: .space 1024
.text
# These lines opens and reads the file containing text to be modified
main:
li $v0, 13 # System call to open file, $v0 set to file descriptor
# $v0 negative if failed to open file
la $a0, file # Load file to read, $a0 set to address of string
# containing file name
li $a1, 0 # Set read-only flag
li $a2, 0 # Set mode
syscall
add $s0, $v0, $zero # Save file descriptor in $v0 to new register $s0
# because $v0 will be used in other system calls
blt $v0, 0, err # Go to handler if failed to open file
# These lines read text from file
read:
li $v0, 14 # System call to read file
add $a0, $s0, $zero # Load file descriptor to $a0
la $a1, buffer # Set $a1 to address of input buffer where
# text will be loaded to
li $a2, 1024 # Set $a2 to number of characters to read
syscall
#after read, $v0 will have number of bytes read
#set last byte to null
la $a0, buffer
add $a0, $a0, $v0 #address of byte after file data
sb $zero, 0($a0)
#initialize some registers
init:
li $t0, 0 # $t0 will be message character iterator i
# initialize i=0
add $s1, $a1, $zero # save address start of buffer
#loop to count characters, exclude white spaces and
loop:
add $s2, $s1, $t0 # $s2 <= A + i, address of current character
# A: address start of buffer
lb $s3, 0($s2) # load char in message[i] to $s3
beq $s3, $zero, print #null, reached end of buffer
addi $t0, $t0, 1 #i++
j loop #continue counting
# Print Data to console
print:
li $v0, 1 # System call to print integer
add $a0, $t0, $zero # Load to $a0 integer to print
syscall
#print "File contents:"
li $v0, 4 # System call to print string
la $a0, pstring # Load to $a0 string to print
syscall
#print actual file contents
li $v0, 4 # System call to print string
la $a0, buffer # Load to $a0 string to print
syscall
# Close File
close:
li $v0, 16 # Close File Syscall
add $a0, $s0, $zero # Load File Descriptor
syscall
j done # Goto done
# Error
err:
li $v0, 4 # System call to print string
la $a0, fnf # Load Error String
syscall
# Done
done:
li $v0, 10 # Exit Syscall
syscall
这是程序读取的文件。它被称为 input.txt。
这是非常有用的,但我希望有更多的图片 哇!!!!!!!!!!!太酷了! 我认为你应该写一篇关于这个问题的后续文章。我们需要像您这样更有见地的意见。 伟大的!再写一个!
程序需要编辑 .txt 文件,使句号后的第一个字母、换行符(换行符)、感叹号或问号大写,并去掉所有不需要的大写。
我知道我想使用 ASCII 码和异或位来更改 ASCII 字符,然后转换为字母。这是因为十进制的位序列“00100000”32可以与逻辑运算符“XOR”一起使用来改变大小写。
8 位 ASCII 表示 大写字母“A”是 01000001。如果将其与 0010000 进行异或运算,您将得到 01100001,即小写字母“a”的 ASCII 码。
但我只能对字母执行此操作,所有特殊字符保持不变。
所以我认为我需要使用如下代码: xori $s3,$s3,32
不知道如何在我的程序中实现这一点。感谢您的帮助。
【问题讨论】: