MIPS Floating Point Division Output

1k views Asked by At

I am new in mips and i got this assignment that asks me to take 2 inputs from user and divide them and get a floating point output. The problem is the output comes out like this 0.000000000, not the predicted output this is my code

   .data
   str1: .asciiz "Enter a: "
   str2: .asciiz "Enter b: "
   str3: .asciiz " a/b = "
   .text

  main: li $v0, 4
  la $a0, str1
  syscall

  li $v0, 6
  syscall 
  add $s0, $v0, $zero

  li $v0, 4
  la $a0, str2
  syscall

  li $v0, 6
  syscall
  move $s1, $v0

  div  $s0, $s1


  li $v0, 4
  la $a0, str3
  syscall

  li $v0, 2
  move $a0, $t0
  syscall



  li $v0, 10
  syscall

what should i do?

1

There are 1 answers

0
Wajiha Batool On
  This code works for me.
  .data
  str1: .asciiz "Enter a: "
  str2: .asciiz "Enter b: "
  str3: .asciiz " a/b = "
 .text
  .globl main
  main: 
  #prompt for "a"
  li $v0, 4
  la $a0, str1
  syscall

  #User input for "a"
  li $v0, 6  #The float value that is read is will be in $f0 register
  syscall 
  mov.s $f3, $f0  #moving the value of "a" into f3 to reuse f0

  #prompt for "b"
  li $v0, 4
  la $a0, str2
  syscall

  #user input for "b"
  li $v0, 6 #The float value that is read is will be in $f0 register
  syscall
  mov.s $f4, $f0

  #Dividing "a" and "b" 
  div.s $f12 $f3 $f4

  #prompt for "a/b"  
  li $v0, 4
  la $a0, str3
  syscall

  #Displaying contents of f12
  li $v0, 2
  syscall

  li $v0, 10
  syscall