1
.text
la $t5, prompt
la $t6, prompt_char
la $t7, prompt_loop

loop:
la $t4, 0 #count


askForString:
la $a0, prompt
li $v0, 4
syscall

li $v0,8
li $a1, 5 #text einlesen
syscall

j quit

quit:
la $a0, ($t7)
li $v0, 4   #info
syscall

li $a1, 5 #text einlesen
li $v0,5
syscall

beq $v0,1,askForString

exit:

.data
prompt: .asciiz "\nPlease enter text\n"
prompt_char: .asciiz "\njetzt bitte ein Zeichen\n"
prompt_loop: .asciiz "\nAgain: 1, Exit: 0.\n"
endl: .asciiz "\n\n"

The problem if i continue the loop my text stored in "prompt"(syscall 4) will be overridden by the input(syscall 5). do i need to clean $a0 or what is the problem. please help

My Result:

Please enter text

aa

Again: 1, Exit: 0.

1

aa (here should be "Please enter text")

1

Again: 1, Exit: 0.

1

1 (here should be "Please enter text")

0

Again: 1, Exit: 0.

0

-- program is finished running (dropped off bottom) --

Michael
  • 57,169
  • 9
  • 80
  • 125
beceras
  • 11
  • 1
  • As [the documentation](https://courses.missouristate.edu/KenVollmar/mars/Help/SyscallHelp.html) states, system call 8 will store the input at the address contained in `$a0`. – Michael Jul 05 '18 at 04:38

1 Answers1

0

You need a new memory location for your input string:

.text
la $t5, prompt
la $t6, prompt_char
la $t7, prompt_loop

loop:
la $t4, 0 #count


askForString:
la $a0, prompt
li $v0, 4
syscall

li $v0,8
la $a0, input  #### --> Other address here
li $a1, 5 #text einlesen
syscall

j quit

quit:
la $a0, ($t7)
li $v0, 4   #info
syscall

li $a1, 5 #text einlesen
li $v0,5
syscall

beq $v0,1,askForString

exit:

.data
prompt: .asciiz "\nPlease enter text\n"
prompt_char: .asciiz "\njetzt bitte ein Zeichen\n"
prompt_loop: .asciiz "\nAgain: 1, Exit: 0.\n"
endl: .asciiz "\n\n"
input: .space 128  ### --> Some space to put the input
Patrik
  • 2,695
  • 1
  • 21
  • 36