Question
Can someone tell me what I'm doing wrong with my MIPS code in MARS Write a MIPS codes that perform the following: Request the following
Can someone tell me what I'm doing wrong with my MIPS code in MARS
Write a MIPS codes that perform the following:
Request the following information from the user:
First Name,
Last Name,
Age,
Gender,
Phone
Get each input from the user
Write this information into a file with a comma after each field.
Ask to user entering -1 if wants to exit otherwise continue updating the entered info
0 if the user wants to reenter the information
1 to place information into a text document
Exit the program by showing an exit message.
Here is 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
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started