跳转到内容

MIPS 汇编/浮点指令

来自维基教科书,开放世界中的开放书籍

浮点加法的整数实现

#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

进一步阅读

[编辑 | 编辑源代码]
华夏公益教科书