0

I need to take input from the user a floating point array and then print it. I tried the following code:-

.text
.globl main
main:

 la $s0,size
 lw $s1,0($s0)      # size in $s1
 ori $s2,$zero,0    # i in $s2
 la $s3,arr         # arr in $s3

 li $v0,4
 la $a0,msg1
 syscall

 L1:
  beq $s2,$s1,DONE
  li $v0,6
  syscall
  swc1 $f0,0($s3)
  j UPDATE

 UPDATE:
  addi $s3,$s3,4
  addi $s1,$s1,1
  j L1

 DONE:
  li $v0,4
  la $a0,msg2
  syscall

  la $t0,arr
  ori $t1,$zero,0
  L2:
   beq $t1,$s1,EXIT
   lwc1 $f20,0($t0)
   li $v0,2
   mov.s $f12,$f20
   syscall
   addi $t0,$t0,4
   addi $t1,$t1,1
   j L2

  EXIT:
  li $v0,10
  syscall
    .data
  size: .word  9
  arr:  .float  0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0 
  msg1: .asciiz "Enter the elements:-"
  msg2: .asciiz "The elements are:-"  

When i give the input, there is a runtime exception 'invalid float input' at syscall 6. Please help!!!

1
  • If you have a helpful answer you should accept it. Click on checkmark under upvote/downvote counter. This will mark the question as "answered" and provide you with small reputation bonus. See How do I ask FAQ article. Commented Sep 27, 2012 at 7:54

1 Answer 1

1

I guess you are using , as the decimal point instead of ..

E.g.: instead of entering 3.14159 you are entering 3,14159 which is not expected at least by MARS.

Aside from that, I think the line addi $s1,$s1,1 in your code should be addi $s2,$s2,1, as you seem to be using $s2 to hold the current value of your index counter.

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks for pointing out the silly error... It worked on changing $s1 to $s2.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.