Question

Write a MIPS Assembly language program to request a file name from the user, open the...

Write a MIPS Assembly language program to request a file name from the user, open the file, read the contents, and write it out to the console.

0 0
Add a comment Improve this question Transcribed image text
Answer #1

.data  

msg1: .asciiz "Enter the file name: "

msg2: .asciiz "Output:\n"

filename: .ascii ""   

buffer: .space 1024

.text

#prints the message

li $v0, 4 #system call for print string

la $a0, msg1 #msg to display

syscall #Display the message

#take the filename from user

li $v0, 8 #8 for take the input from user

la $a0, filename #store the file name

li $a1, 30 #Size of file name in bytes

syscall   

# Open file for reading

li $v0, 13 # 13 for open file

la $a0, filename

li $a1, 0 # assign zero for read operation

li $a2, 0 # permissions

syscall # open a file

move $s0, $v0 # move the file descriptor to $s0

# reading from file

li $v0, 14 # 14 for reading from file

move $a0, $s0

la $a1, buffer # address of buffer from which to read

li $a2, 1024 # No of bytes to read

syscall # read from file

#prints the message

li $v0, 4 #4 for print string

la $a0, msg2 #msg to display

syscall #Display the message

# Printing File Content

li $v0, 4 # 4 to print string

la $a0, buffer # buffer contains the string

syscall   

#Closing the file

li $v0, 16 # 16 close the file

add $a0, $s0, $0 # $s0 contains fd

syscall

#Exit from program

li $v0, 10

syscall

Add a comment
Know the answer?
Add Answer to:
Write a MIPS Assembly language program to request a file name from the user, open the...
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