Question

How could i read values so i can store them in memory after? I need to get the user to input values and then press enter so i can get those values and work with them.

Thank you

Was it helpful?

Solution

You should use service 5 to read an integer, 6 to read a float, 7 for a double and service 8 to read a string. See MARS reference for syscall services provided.

Here goes an example that reads an integer and a string from console and holds the results in variables number and buffer:

.data
  number: .word 0
  buffer: .space 80

 .text
   li $v0, 5 # service 5 reads integer from console
   syscall

   sw $v0, number # Store read integer into number
   li $v0, 8 # service 8 reads a string
   la $a0, buffer
   li $a1, 80  # buffer size
   syscall  # input text will be stored in buffer 

   li $v0, 7  # service 7 reads double
   syscall # $f0-$f1 contains the double read
   mov.d $f2, $f0
   syscall # read another double

   div.d $f12, $f2, $f0  # Divide the first double by the second double
   li $v0, 3
   syscall  # Print result of division
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top