Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can someone help me with this MIPS problem on MARS, please look at my code. QUESTION: Generate a txt file with the following info in

Can someone help me with this MIPS problem on MARS, please look at my code.

QUESTION:

Generate a txt file with the following info in each line.

- First Name,

- Last Name,

- Age,

- Gender,

- Phone

Write a MIPS codes that performs the following tasks:

Request a text file name from the user.

Trim the file name

Open the file with the entered file name by the user.

Read the file until the end of the text.

Show the text in the file at the console.

Exit the program by showing an exit message.

MY CODE:

.data

prompt1: .asciiz "Enter first name: "

firstname: .space 20

prompt2: .asciiz "Enter last name: "

lastname: .space 20

prompt3: .asciiz "Enter Age: "

age: .space 20

prompt4: .asciiz "Enter Gender: "

gender: .space 20

prompt5: .asciiz "Enter Phone Number: "

PhoneNumber: .space 20

prompt6: .asciiz "(-1) To exit:"

prompt7: .asciiz "(0) To update information:"

prompt8: .asciiz "(1) To write infromation into a file with a comma after each field:"

ExitEnter: .space 20

fin: .ascii ""

msg1: .asciiz "Please input name for text file: "

exiting: .asciiz "Thank you for the information. Saving and closing the file and exiting the program."

inputbuffer: .space 51

buffer: .asciiz ""

comma: .asciiz ","

newline: .asciiz " "

.text

li $s2, -1

li $s3, 0

li $s4, 1

filename:

li $v0, 4 #Input File name from user

la $a0, msg1

syscall

li $v0, 8

la $a0, fin #Use File Name from user and save it

li $a1, 21

syscall

fileopen:

li $v0, 13 #open file name from user

la $a0, fin #open file.txt

li $a1, 1 #flag for writing

li $a2, 0

syscall

move $s0, $v0

jal string

fileread:

# reading from file 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, 100000 # hardcoded buffer length

syscall # read from file

#Clean up name input for file to be read

nameClean:

li $t0, 0 #loop counter

li $t1, 21 #loop end

clean:

beq $t0, $t1, L5

lb $t3, fin($t0)

bne $t3, 0x0a, L6

sb $zero, fin($t0)

L6:

addi $t0, $t0, 1

j clean

L5:

jr $ra

#print strings for FirstName - Phone Number

string:

#First Name

li $v0, 4 #prompt user for First Name

la $a0, prompt1 #open prompt

syscall

li $v0, 8

la $a0, firstname

li $a1, 20

syscall

jr $ra

filewritefirstname:

li $v0, 15 #save prompt of first name, and write to file

move $a0, $s6

la $a1, firstname

li $a2, 20

syscall

#Last Name

li $v0, 4 #prompt user for Last Name

la $a0, prompt2 #open prompt

syscall

li $v0, 8

la $a0, lastname

li $a1, 20

syscall

jr $ra

filewritelastname:

li $v0, 15 #save prompt of last name, and write to file

move $a0, $s6

la $a1, lastname

li $a2, 20

syscall

#Age

li $v0, 4 #prompt for age

la $a0, prompt3

syscall

li $v0, 8

la $a0, age

li $a1, 20

syscall

filewriteage:

li $v0, 15 #write age to file

move $a0, $s6

la $a1, age

li $a2, 20

syscall

#Gender

li $v0, 4 #prompt for gender

la $a0, prompt4

syscall

li $v0, 8

la $a0, gender

li $a1, 20

syscall

filewritegender:

li $v0, 15 #write gender to file

move $a0, $s6

la $a1, gender

li $a2, 20

syscall

#Phone

li $v0, 4 #prompt for Phone Number

la $a0, prompt5

syscall

li $v0, 8

la $a0, PhoneNumber

li $a1, 20

syscall

filewritephone:

li $v0, 15 #write Phone Number to file

move $a0, $s6

la $a1, PhoneNumber

li $a2, 20

syscall

exitenter:

#Exit Enter

li $v0, 4 #prompt to exit, or continue writing

la $a0, prompt6 #-1

syscall

li $v0, 4

la $a0, prompt7 #0

syscall

li $v0, 4

la $a0, prompt8 #1

syscall

li $v0, 8

la $a0, ExitEnter #write to file

li $a1, 20

syscall

write:

#write to file

beq $s2, -1,Exit

beq $s3, 0, Exit

beq $s4, 1, Exit

j string

#exit file

Exit:

li $v0, 16

la $a0, exiting

move $a0, $s6

syscall

exit

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_2

Step: 3

blur-text-image_3

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

Databases Organizing Information Digital And Information Literacy

Authors: Greg Roza

1st Edition

1448805929, 978-1448805921

More Books

Students also viewed these Databases questions

Question

Why is it important to match sources and methods of recruitment?

Answered: 1 week ago