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  
    fileName: .asciiz ""      # To store file name
    buffer: .space 1024
    buffer_1: .space 20
    str1:  .asciiz "Please enter the file name"
.text
    la $a0, str1    # Print a prompt asking for the filename
    li $v0, 4
    syscall

    li $v0, 8       # read the  input

    la $a0, buffer_1  # load byte space into address
    li $a1, 20      # allocation of byte space to string

    move $t0, $a0   # save string to t0
    syscall
# Open file for reading

    li   $v0, 13          # system call for open file
    la   $a0, fileName      # name of input file
    li   $a1, 0           # read flag
    li   $a2, 0           
    syscall               # file opened
    move $s0, $v0         # file descriptor saved here


# reading from file just opened

    li   $v0, 14        # reading from file system call
    move $a0, $s0       # file descriptor 
    la   $a1, buffer    # buffer address
    li   $a2,  11       #  predefined buffer length
    syscall             # Trigger reading from file


# Printing File Content
    li  $v0, 4          # system call function for printing a string
    la  $a0, buffer
    syscall             # print the values

    li $v0, 10      # Program Exit call
    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
ADVERTISEMENT