0

そのため、浮動小数点の追加がどのように機能するかをよりよく理解できるように、MIPSアセンブリコードでプログラムを作成しようとしています。浮動小数点数が1ビットの符号、8ビットの指数、および23ビットの小数部にどのように分割されるかを理解しています。ユーザーから2つの入力を取得し、mtc1とmfc1(入力と出力用)以外の浮動小数点命令を使用せずにそれらを追加するプログラムを作成しました。1 + 2を追加すると、2.74804688になるため、コードにバグがあります。私はまだコードをデバッグしようとしていますが、問題を把握できないようです。誰か助けていただければ幸いです。

これは私のコードです(ユーザー入力を除く...最初の浮動小数点値は$ s0にあり、2番目は$ s1にあります)

#Integer implementation of floating-point addition
#Initialize variables
add $s0,$t0,$zero #first integer value
add $s1,$t1,$zero #second integer value
add $s2,$zero,$zero #initialize sum variable to 0
add $t3,$zero,$zero #initialize SUM OF SIGNIFICANDS value to 0

#get EXPONENT from values
sll $s5,$s0,1 #getting the exponent value
srl $s5,$s5,24 #$s5 = first value EXPONENT

sll $s6,$s1,1 #getting the exponent value
srl $s6,$s6,24 #$s6 = second value EXPONENT

#get SIGN from values
srl $s3,$s0,31 #$s3 = first value SIGN
srl $s4,$s1,31 #$s4 = second value SIGN

#get FRACTION from values
sll $s7,$s0,9
srl $s7,$s0,9 #$s7 = first value FRACTION
sll $t8,$s1,9
srl $t8,$s1,9 #$t8 = second value FRACTION

#compare the exponents of the two numbers
compareExp: ######################

beq $s5,$s6, addSig
blt $s5,$s6, shift1 #if first < second, go to shift1
blt $s6,$s5, shift2 #if second < first, go to shift2
j compareExp

shift1: #shift the smaller number to the right
srl $s7,$s7,1 #shift to the right 1
addi $s5,$s5,1
j compareExp

shift2: #shift the smaller number to the right
#srl $s0,$s0,1 #shift to the right 1
#j compareExp
srl $t8,$t8,1 #shift to the right 1
addi $s6,$s6,1
j compareExp

addSig:

add $t3,$s7,$t8 #Add the SIGNIFICANDS

li $v0, 4
la $a0, sum
syscall

li $v0, 1
move $a0, $t3
syscall

j result

result:
li $v0, 4
la $a0, newline
syscall

sll $t4,$s3,31 #SIGN
#FRACTION
sll $t5,$s6,23 #EXPONENT
add $t6,$t4,$t5
add $t6,$t6,$t3

li $v0, 4
la $a0, sum2
syscall

li $v0, 1
move $a0, $t6
syscall

li $v0, 4
la $a0, newline
syscall

li $v0, 4
la $a0, sum2
syscall

li $v0,2
mtc1 $t6,$f12
syscall
jr $31
# END OF PROGRAM
4

1 に答える 1

0

特にMIPSについてはわかりませんが、多くの場合、浮動小数点値には、小数部の最上位ビットの直前に暗黙の「1」ビットがあります。ゼロは、暗黙のビットを持たない特殊なケースです。

于 2011-03-24T22:07:04.390 に答える