Question

I need help with MIPS-32 assembly language. My question is how to open an existing text...

I need help with MIPS-32 assembly language.

My question is how to open an existing text file, read from the file, display contents, and close the file read in MIPS32 using MARS 4.5 MIPS simulator.

Existing text file is testfile.txt

testfile.txt contains: 001010100101001100

0 0
Add a comment Improve this question Transcribed image text
Answer #1
.data  
fin: .asciiz "testfile.txt"      # enter the filename for input
buffer: .space 128
buffer1: .asciiz "\n"
val : .space 128
.text

################################################ fileRead:
 Opening an existing  file for reading

li   $v0, 13       # system call for open file
la   $a0, fin      # input file name
li   $a1, 0        # flag for reading
li   $a2, 0        # mode is ignored
syscall            # open  file 
move $s0, $v0      # save the file descriptor 

# reading from the opened file 

li   $v0, 14       # system call for reading from file
move $a0, $s0      # file descriptor 
la   $a1, buffer   # address of buffer from which to read
li   $a2,  6       # buffer length
syscall            # read from the file
li  $v0, 4          # 
la  $a0, buffer     # buffer contains the values
syscall             # print int

lb $t1 , buffer

# reading from the file that is just opened

li   $v0, 14       # system call for reading from file
move $a0, $s0      # file descriptor 
la   $a1, buffer   # address of buffer from which to read
li   $a2,  6       # buffer length
syscall            # read from file
li  $v0, 4          # 
la  $a0, buffer     # buffer containing values
syscall             # print

## sh  $t5 , val($0)    #sw    $t5, theArray($t0)

--> Closing file 

li   $v0, 16       # system call for close file
move $a0, $s6      # file descriptor to close
syscall            # close file
Add a comment
Know the answer?
Add Answer to:
I need help with MIPS-32 assembly language. My question is how to open an existing text...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT