bethesda 0 Newbie Poster

Hi! First of all, I'm new to this, so I apologise in advance if this is a really simple thing...
I am trying to write a code in assembly MIPS, in wich the program asks the user for the name of a file where it will read the text on it and copy it to another text file.
I created this code below where the name of the file is given by the variable msg3 ( the user prompt doesn't do anything yet...) and this code seems to work (i.e. the result file presents the same text has file1.txt)

.data
	msg1: .asciiz "Name of file: "
	msg3: .asciiz "file1.txt"		#File to read from
	file: .asciiz "result.txt"			# File to Write to
	.align 4		
	str_value: .asciiz "caracas"		# Variable for keyboard input

	test: .space 80				# Buffer

.text
	main:
		la $a0, msg1
		jal print_string
		la $a0, str_value			# Loads the name of the file
		jal read_string

### File for Reading
		li $v0, 13			# System call to open file
		la $a0, msg3		# Name of the file
		li $a1, 0				# Flags Open to Read(0: read, 1: write) 
		syscall
		move $t0, $v0			# Saves fd in $t0

		li $v0, 14			# System call to read from file
		la $a1, test			# Buffer where to write
		li $a2, 9				# Number of characters to read
		move $a0, $t0			# Saves fd in $a0
		syscall

		li $v0, 16			# System call to close file
		move $a0, $t0			# Return fd
		syscall

### File for Writing
		li $v0, 13			# System to open file
		la $a0, file			# Name of the file
		li $a1, 1				# Flags Open to Write(0: read, 1: write)
		syscall
		move $t0, $v0			# Saves fd

		li $v0, 15			# System call to write on file
		la $a1,teste			# Buffer where to write
		li $a2, 80			# Number of characters to read
		move $a0, $t0
		syscall

		li $v0, 16			# System call to close file
		move $a0, $s6			# Returns fd
		syscall

	finish:
		li $v0, 10			# System call para terminar a execucao
		syscall
### Functions
read_string:
	li $v0, 8					
	la $a1, 80
	syscall
	jr $ra					

print_string:
	li $v0, 4					
	syscall
	jr $ra

Then, I altered the code, so the input by the user to be saved in the str_value variable, wich is used by the program to acess the file. This time, the program, although it works, it doesn't do what it is required (i.e. the result.txt file appears empty/with spaces). I'm tired of looking at it all day long and I don't see what I'm doing wrong.....can someone help, please? (to be noted that in the prompt, the user should write "file1.txt"

.data
	msg1: .asciiz "Name of file: "
	msg3: .asciiz "file1.txt"		#File to read from
	file: .asciiz "result.txt"			# File to Write to
	.align 4		
	str_value: .asciiz "caracas"		# Variable for keyboard input

	test: .space 80				# Buffer

.text
	main:
		la $a0, msg1
		jal print_string
		la $a0, str_value			# Loads the name of the file
		jal read_string

### File for Reading
		li $v0, 13			# System call to open file
		la $a0, str_value		# Name of the file
		li $a1, 0				# Flags Open to Read(0: read, 1: write) 
		syscall
		move $t0, $v0			# Saves fd in $t0

		li $v0, 14			# System call to read from file
		la $a1, test			# Buffer where to write
		li $a2, 9				# Number of characters to read
		move $a0, $t0			# Saves fd in $a0
		syscall

		li $v0, 16			# System call to close file
		move $a0, $t0			# Return fd
		syscall

### File for Writing
		li $v0, 13			# System to open file
		la $a0, file			# Name of the file
		li $a1, 1				# Flags Open to Write(0: read, 1: write)
		syscall
		move $t0, $v0			# Saves fd

		li $v0, 15			# System call to write on file
		la $a1,teste			# Buffer where to write
		li $a2, 80			# Number of characters to read
		move $a0, $t0
		syscall

		li $v0, 16			# System call to close file
		move $a0, $s6			# Returns fd
		syscall

	finish:
		li $v0, 10			# System call para terminar a execucao
		syscall
### Functions
read_string:
	li $v0, 8					
	la $a1, 80
	syscall
	jr $ra					

print_string:
	li $v0, 4					
	syscall
	jr $ra
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.