Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

the given code is: #name: #studentID: .data #Must use accurate file path. #file paths in MARS are relative to the mars.jar file. # if you

image text in transcribed

the given code is:

#name:

#studentID:

.data

#Must use accurate file path.

#file paths in MARS are relative to the mars.jar file.

# if you put mars.jar in the same folder as test2.txt and your.asm, input: should work.

input: .asciiz "test2.txt" #used as input

output: .asciiz "copy.pgm" #used as output

buffer: .space 2048 # buffer for upto 2048 bytes

.text

.globl main

main:

la $a0,input #readfile takes $a0 as input

jal readfile

la $a0, output #writefile will take $a0 as file location

la $a1,buffer #$a1 takes location of what we wish to write.

jal writefile

li $v0,10 # exit

syscall

readfile:

#Open the file to be read,using $a0

#Conduct error check, to see if file exists

# You will want to keep track of the file descriptor*

# read from file

# use correct file descriptor, and point to buffer

# hardcode maximum number of chars to read

# read from file

# address of the ascii string you just read is returned in $v1.

# the text of the string is in buffer

# close the file (make sure to check for errors)

writefile:

#open file to be written to, using $a0.

#write the specified characters as seen on assignment PDF:

#P2

#24 7

#15

#write the content stored at the address in $a1.

#close the file (make sure to check for errors)

(a) Using the template fileIO.asm as a starting point, write a MIPS procedure readfile that takes as its argument the address of a string that contains a valid filename, and then uses appropriate syscalls to read from that input file and then simply prints the content of that file to the screen. In the template there are two input files called test1.txt and test2.txt which you should test. To accomplish this task we allow you to create a large buffer, i.e., one that is larger than the expected number of ASCII characters (bytes) in the input file. The body of your code should work by calling the procedure you have written. The procedure should open the file, read its content as ASCII characters, store the content in the buffer, print the content to the screen, and then close the file. For your reference a more complete set of MIPS syscalls implemented in MARS, along with clear documentation on how to use each, is here: http://courses.missouristate.edu/kenvollmar/mars/help/syscallhelp.html (b) We shall now build on the above example. Following the process of reading the file testl.trt after which the ASCII characters have been read into the buffer, we shall call a second MIPS procedure called writefile. This procedure should open a file called copy.pgm, should then write the following information to that file: P2 24 7 15 Then it should write out the content that was read into the buffer. It should then close the (5 marks)Error statements should be printed if there are any errors in opening the file. If things are working properly when you view copy.pgm with a suitable image viewer, e.g., gimp, you should see something interesting (a) Using the template fileIO.asm as a starting point, write a MIPS procedure readfile that takes as its argument the address of a string that contains a valid filename, and then uses appropriate syscalls to read from that input file and then simply prints the content of that file to the screen. In the template there are two input files called test1.txt and test2.txt which you should test. To accomplish this task we allow you to create a large buffer, i.e., one that is larger than the expected number of ASCII characters (bytes) in the input file. The body of your code should work by calling the procedure you have written. The procedure should open the file, read its content as ASCII characters, store the content in the buffer, print the content to the screen, and then close the file. For your reference a more complete set of MIPS syscalls implemented in MARS, along with clear documentation on how to use each, is here: http://courses.missouristate.edu/kenvollmar/mars/help/syscallhelp.html (b) We shall now build on the above example. Following the process of reading the file testl.trt after which the ASCII characters have been read into the buffer, we shall call a second MIPS procedure called writefile. This procedure should open a file called copy.pgm, should then write the following information to that file: P2 24 7 15 Then it should write out the content that was read into the buffer. It should then close the (5 marks)Error statements should be printed if there are any errors in opening the file. If things are working properly when you view copy.pgm with a suitable image viewer, e.g., gimp, you should see something interesting

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions