我如何将2.5转换为mips中的二进制ieee格式?

时间:2014-05-14 16:12:35

标签: binary mips ieee-754

有没有办法将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

但是在小数部分之后停留,即:小数部分。

谢谢!

p.s:我正在使用qtspim

1 个答案:

答案 0 :(得分:0)

考虑以下伪代码:

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