Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.
Write a program to read the following text(words.txt) filePreview the documentView in a new window line by line, detect which words are palindromes,...
Write a program to read the following text(words.txt) filePreview the documentView in a new window line by line, detect which words are palindromes, writes them to another file and counts them.
The following code shows how to write a file in the MARS assembler simulator (Links to an external site.):
# Sample MIPS program that writes to a new file.# by Kenneth Vollmar and Pete Sanderson
.datafout: .asciiz "testout.txt" # filename for outputbuffer: .asciiz "The quick brown fox jumps over the lazy dog.".text################################################################ Open (for writing) a file that does not existli $v0, 13 # system call for open filela $a0, fout # output file nameli $a1, 1 # Open for writing (flags are 0: read, 1: write)li $a2, 0 # mode is ignoredsyscall # open a file (file descriptor returned in $v0)move $s6, $v0 # save the file descriptor ################################################################ Write to file just openedli $v0, 15 # system call for write to filemove $a0, $s6 # file descriptor la $a1, buffer # address of buffer from which to writeli $a2, 44 # hardcoded buffer lengthsyscall # write to file################################################################ Close the file li $v0, 16 # system call for close filemove $a0, $s6 # file descriptor to closesyscall # close file###############################################################
A quick tip is a procedure that reads the file a character at a time, each character is assumed to be in ASCII and takes up a byte. You should test your code with the file containing one thousand wordsPreview the documentView in a new window. Please assume that the file is in the current directory where the mips assembly file exists. Please submit only .asm files. if you submit any other type of file, I will not grade it. Include test cases in your code with the one thousand words file(thousand.txt).
The following code helps as well:
# Read and echo file on a character by character basis# David A. Reimann# April 2008
.textmain:
# Open File
li $v0, 13 # 13=open filela $a0, file # $a2 = name of file to readadd $a1, $0, $0 # $a1=flags=O_RDONLY=0add $a2, $0, $0 # $a2=mode=0syscall # Open FIle, $v0<-fdadd $s0, $v0, $0 # store fd in $s0
# Read 4 bytes from file, storing in buffer
li $v0, 14 # 14=read from fileadd $a0, $s0, $0 # $s0 contains fdla $a1, buffer # buffer to hold intli $a2, 4 # Read 4 bytessyscall
li $v0, 1 # 1=print intlw $a0, buffer # buffer contains the intsyscall # print int
# Close File
done:li $v0, 16 # 16=close fileadd $a0, $s0, $0 # $s0 contains fdsyscall # close file
# Exit Gracefully
li $v0, 10syscall
.data
file:.asciiz "/home/sleightlab/crap" # File name.word 0buffer: .space 4 # Place to store character