我如何将2.5转换成二进制ieee格式在mips



是否有任何方法将2.5存储为字符串,然后将其转换为MIPS中的二进制ieee格式?

小数点前的部分已经写完了。使用以下代码:

.data

promt:  .asciiz "Enter decimal number:"
output: .asciiz "The number in binary is:"
    .text
    .globl main
main:
    la $a0, promt #put address of the string in $a0
    li $v0,4
    syscall
    li $v0, 5 # code for input
    syscall
##input is in $v0, we will have to save it in a saved register
    move $t0,$v0
    addi $t2, $0,2  #making $t2 '2'
    addi$sp, $sp, -32   #makinf stack
    addi $t5, $zero, 0
loop:
    div $t0,$t2
    mflo $t0    # mov from hi
    mfhi $t1    #mov from low
    sw $t1, 0($sp)  #copy $s1 to stack
    addi $sp, $sp, 4
    addi $t5, $t5, 1
    bgtz $t0, loop # if s0 greater than zero than           
    addi $sp, $sp, -4
printing:
    li $v0,1
    lw $a0, 0($sp)
    syscall
    addi $sp, $sp, -4
    addi $t5, $t5, -1
    bgtz $t5, printing
    addi $sp, $sp, 32
    li $v0, 10
    syscall

但是卡在小数点后的部分,即小数1。

谢谢!

p。s:我正在使用qtspim

考虑以下伪代码:

pointPos := positionOfDecimalPointInString()
sum := 0
for i := pointPos - 1 downTo 0:
    sum := sum * 10
    sum := sum + string[i] - '0'
fraction := 0    
for i := length(string) downTo pointPos + 1:
    fraction := fraction + string[i] - '0'
    fraction := fraction / 10
return sum + fraction

相关内容

  • 没有找到相关文章

最新更新