MIPS浮点除法输出

时间:2016-12-18 21:28:45

标签: output mips floating

我是mips的新手,我得到了这个任务,要求我从用户那里获取2个输入并将它们分开并获得浮点输出。 问题是输出就像这个0.000000000,而不是预测的输出 这是我的代码

   .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

我该怎么办?

1 个答案:

答案 0 :(得分:0)

  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