MIPS Creating a file name from User Input, and Reading the data in Assembly Language -
i'm having troubles creating file in mips, or mars simulator, has user input file name, while writing , reading contents. if hard-code file name, "file.txt", work. wish user input file name , use that. overall, i'm having troubles getting user input file name. want write fields first name, last name, age, gender, , phone number file inputted user.
.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 "to exit enter (-1) otherwise update entered info: " exitenter: .space 20 fin: .ascii "" msg1: .asciiz "please input name text file: " exiting: .asciiz "thank information. saving , closing file , exiting program." inputbuffer: .space 51 buffer: .asciiz "" comma: .asciiz "," newline: .asciiz "\r\n" #john nguyen #assignment 2 .text li $s2, -1 filename: li $v0, 4 #input file name user la $a0, msg1 syscall li $v0, 8 la $a0, fin #use file name user , save li $a1, 21 syscall fileopen: li $v0, 13 #open file name user la $a0, fin #open file.txt li $a1, 1 #flag writing li $a2, 0 syscall move $s0, $v0 jal string fileread: # reading file opened li $v0, 14 # system call reading file move $a0, $s0 # file descriptor la $a1, buffer # address of buffer read li $a2, 100000 # hardcoded buffer length syscall # read file jr $ra #clean name input file 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 firstname - phone number string: #first name li $v0, 4 #prompt user first name la $a0, prompt1 #open prompt syscall li $v0, 8 la $a0, firstname li $a1, 20 syscall filewritefirstname: li $v0, 15 #save prompt of first name, , write file move $a0, $s6 la $a1, firstname li $a2, 20 syscall #last name li $v0, 4 #prompt user last name la $a0, prompt2 #open prompt syscall li $v0, 8 la $a0, lastname li $a1, 20 syscall filewritelastname: li $v0, 15 #save prompt of last name, , write file move $a0, $s6 la $a1, lastname li $a2, 20 syscall #age li $v0, 4 #prompt age la $a0, prompt3 syscall li $v0, 8 la $a0, age li $a1, 20 syscall filewriteage: li $v0, 15 #write age file move $a0, $s6 la $a1, age li $a2, 20 syscall #gender li $v0, 4 #prompt gender la $a0, prompt4 syscall li $v0, 8 la $a0, gender li $a1, 20 syscall filewritegender: li $v0, 15 #write gender file move $a0, $s6 la $a1, gender li $a2, 20 syscall #phone li $v0, 4 #prompt phone number la $a0, prompt5 syscall li $v0, 8 la $a0, phonenumber li $a1, 20 syscall filewritephone: li $v0, 15 #write phone number file move $a0, $s6 la $a1, phonenumber li $a2, 20 syscall exitenter: #exit enter li $v0, 4 #prompt exit, or continue writing la $a0, prompt6 syscall li $v0, 8 la $a0, exitenter #write file li $a1, 20 syscall write: #write file beq $s2, -1,exit j string #exit file exit: li $v0, 16 la $a0, exiting move $a0, $s6 syscall
Comments
Post a Comment