FP Calc MP
FP Calc MP
FP Calc MP
data
.word 0x40A00000,0x40A00000
.text
main:
f_add:
lui $t0,0x1001
sub $s0, $s0, $s0
sub $s1, $s1, $s1
lw $s0, 0($t0)
lw $s1, 4($t0)
beq $s0, $0, zero_1_add
beq $s1, $0, zero_2_add
jal infinity_checker_add
srl $t1, $s0, 31 #sign
sll $t1, $t1, 31
sll $t2, $s0, 1
srl $t2, $t2, 24 #exponent
addi $t2, $t2, -127 #remove bias
sll $t3, $s0, 9
srl $t3, $t3, 9 #mantissa
lui $t4, 0x0080
add $t3, $t3, $t4 #mantissa with implied 1
situationA_add:
slt $a0, $t6, $t2
beq $a0, $0, shiftB_sitA_add
j shiftA_sitA_add
shiftA_sitA_add:
sub $t8,$t2,$t6
srlv $t7,$t7,$t8
nor $t7, $t7, $0
addi $t7, $t7, 0x00000001 #2s complement
sub $at, $at, $at
ori $at, $0, 0x100
sll $at, $at, 16 #sign bit
or $t7, $t7, $at
sll $t7, $t7, 7
srl $t7, $t7, 7
add $v0,$t7,$t3
sll $v0, $v0, 7
srl $v0, $v0, 7
sll $a3,$v0,7
srl $a3,$a3,31
sll $a3,$a3,31 #final sign
beq $a3,$0, no_complementA_add
nor $v0, $v0, $0
addi $v0, $v0, 0x00000001
sll $v0, $v0, 7
srl $v0, $v0, 7
add $v1,$v0,$0
jal premature_exit_add
jal normalize
addi $a2, $a1, -24
bltz $a2, no_compfinalA_add
srlv $v0, $v0, $a2 #normalize mantissa
sll $v0, $v0, 9
srl $v0, $v0, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t2, $t2, $a1
addi $t2, $t2, 127
sll $t2, $t2, 23 #final exponent
add $v0, $v0, $t2
add $v0, $v0, $a3 #final sign
sw $v0, 32($t0)
j exit_add
shiftB_sitA_add:
sub $t9,$t6,$t2
srlv $t3,$t3,$t9
nor $t7, $t7, $0
addi $t7, $t7, 0x00000001 #2s complement
sub $at, $at, $at
ori $at,$0,0x100
sll $at, $at, 16 #sign bit
or $t7, $t7, $at
sll $t7, $t7, 7
srl $t7, $t7, 7
add $v0,$t3,$t7
sll $v0, $v0, 7
srl $v0, $v0, 7
sll $a3,$v0,7
srl $a3,$a3,31
sll $a3,$a3,31 #final sign
beq $a3,$0, no_complementB_add
nor $v0, $v0, $0
addi $v0, $v0, 0x00000001
sll $v0, $v0, 7
srl $v0, $v0, 7
add $v1,$v0,$0
jal premature_exit_add
jal normalize
addi $a2, $a1, -24
bltz $a2, no_compfinalB_add
srlv $v0, $v0, $a2 #normalize mantissa
sll $v0, $v0, 9
srl $v0, $v0, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t6, $t6, $a1
addi $t6, $t6, 127
sll $t6, $t6, 23 #final exponent
add $v0, $v0, $t6
add $v0, $v0, $a3
sw $v0, 32($t0)
j exit_add
situationB_add:
slt $a0, $t6, $t2
beq $a0, $0, shiftB_sitB_add
j shiftA_sitB_add
shiftA_sitB_add:
sub $t8,$t2,$t6
srlv $t7,$t7,$t8
nor $t3, $t3, $0
addi $t3, $t3, 0x00000001 #2s complement
sub $at, $at, $at
ori $at,$0, 0x100
sll $at, $at, 16 #sign bit
or $t3, $t3, $at
sll $t3, $t3, 7
srl $t3, $t3, 7
add $v0,$t7,$t3
sll $v0, $v0, 7
srl $v0, $v0, 7
sll $a3,$v0,7
srl $a3,$a3,31
sll $a3,$a3,31 #final sign
beq $a3,$0, no_complementA_add
nor $v0, $v0, $0
addi $v0, $v0, 0x00000001
sll $v0, $v0, 7
srl $v0, $v0, 7
add $v1,$v0,$0
jal premature_exit_add
jal normalize
addi $a2, $a1, -24
bltz $a2, no_compfinalA_add
srlv $v0, $v0, $a2 #normalize mantissa
sll $v0, $v0, 9
srl $v0, $v0, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t2, $t2, $a1
addi $t2, $t2, 127
sll $t2, $t2, 23 #final exponent
add $v0, $v0, $t2
add $v0, $v0, $a3 #final sign
sw $v0, 32($t0)
j exit_add
shiftB_sitB_add:
sub $t9,$t6,$t2
srlv $t3,$t3,$t9
nor $t3, $t3, $0
addi $t3, $t3, 0x00000001 #2s complement
sub $at, $at, $at
ori $at,$0,0x100
sll $at, $at, 16 #sign bit
or $t3, $t3, $at
sll $t3, $t3, 7
srl $t3, $t3, 7
add $v0,$t3,$t7
sll $v0, $v0, 7
srl $v0, $v0, 7
sll $a3,$v0,7
srl $a3,$a3,31
sll $a3,$a3,31 #final sign
beq $a3, $0, no_complementB_add
nor $v0, $v0, $0
addi $v0, $v0, 0x00000001
sll $v0, $v0, 7
srl $v0, $v0, 7
add $v1,$v0,$0
jal premature_exit_add
jal normalize
addi $a2, $a1, -24
bltz $a2, no_compfinalB_add
srlv $v0, $v0, $a2 #normalize mantissa
sll $v0, $v0, 9
srl $v0, $v0, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t6, $t6, $a1
addi $t6, $t6, 127
sll $t6, $t6, 23 #final exponent
add $v0, $v0, $t6
add $v0, $v0, $a3
sw $v0, 32($t0)
j exit_add
pure_add_add:
slt $a0, $t6, $t2
beq $a0, $0, shiftB_add
j shiftA_add
shiftA_add:
sub $t8,$t2,$t6
srlv $t7,$t7,$t8
add $v0,$t7,$t3
add $v1,$v0,$0
jal premature_exit_add
jal normalize
addi $a2, $a1, -24
srlv $v0, $v0, $a2 #normalize mantissa
sll $v0, $v0, 9
srl $v0, $v0, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t2, $t2, $a1
addi $t2, $t2, 127
sll $t2, $t2, 23 #final exponent
add $v0, $v0, $t2
add $v0, $v0, $t1 #final sign
sw $v0, 32($t0)
j exit_add
shiftB_add:
sub $t9,$t6,$t2
srlv $t3,$t3,$t9
add $v0,$t3,$t7
add $v1,$v0,$0
jal premature_exit_add
jal normalize
addi $a2, $a1, -24
srlv $v0, $v0, $a2 #normalize mantissa
sll $v0, $v0, 9
srl $v0, $v0, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t6, $t6, $a1
addi $t6, $t6, 127
sll $t6, $t6, 23 #final exponent
add $v0, $v0, $t6
add $v0, $v0, $t1 #final sign
sw $v0, 32($t0)
j exit_add
no_complementA_add:
add $v1,$v0,$0
jal premature_exit_add
jal normalize
addi $a2, $a1, -24
bltz $a2, no_compfinalA_add
srlv $v0, $v0, $a2 #normalize mantissa
sll $v0, $v0, 9
srl $v0, $v0, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t2, $t2, $a1
addi $t2, $t2, 127
sll $t2, $t2, 23 #final exponent
add $v0, $v0, $t2
add $v0, $v0, $a3 #final sign
sw $v0, 32($t0)
j exit_add
no_compfinalA_add:
sub $a2, $0, $a2
sllv $v0, $v0, $a2 #normalize mantissa
sll $v0, $v0, 9
srl $v0, $v0, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t2, $t2, $a1
addi $t2, $t2, 127
sll $t2, $t2, 23 #final exponent
add $v0, $v0, $t2
add $v0, $v0, $a3 #final sign
sw $v0, 32($t0)
j exit_add
no_complementB_add:
add $v1,$v0,$0
jal premature_exit_add
jal normalize
addi $a2, $a1, -24
bltz $a2, no_compfinalB_add
srlv $v0, $v0, $a2 #normalize mantissa
sll $v0, $v0, 9
srl $v0, $v0, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t6, $t6, $a1
addi $t6, $t6, 127
sll $t6, $t6, 23 #final exponent
add $v0, $v0, $t6
add $v0, $v0, $a3
sw $v0, 32($t0)
j exit_add
no_compfinalB_add:
sub $a2, $0, $a2
sllv $v0, $v0, $a2 #normalize mantissa
sll $v0, $v0, 9
srl $v0, $v0, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t6, $t6, $a1
addi $t6, $t6, 127
sll $t6, $t6, 23 #final exponent
add $v0, $v0, $t6
add $v0, $v0, $a3 #final sign
sw $v0, 32($t0)
j exit_add
infinity_checker_add:
ori $k0,$0,0xff80
sll $k0, $k0, 16
ori $k1, $0, 0x7f80
sll $k1, $k1, 16
beq $s0, $k0, inf3_add
beq $s0, $k1, inf4_add
beq $s1, $k0, inf1_add
beq $s1, $k1, inf2_add
j go_back_add
inf1_add:
beq $s1, $k0, inf_neg_add
j pos_neg_add
inf2_add:
beq $s1, $k1, inf_pos_add
j pos_neg_add
inf3_add:
beq $s1, $k0, inf_neg_add
beq $s1, $k1, pos_neg_add
j inf_neg_add
inf4_add:
beq $s1, $k0, pos_neg_add
beq $s1, $k1, inf_pos_add
j inf_pos_add
inf_pos_add:
or $v0, $v0, $k1
sw $v0, 32($t0)
j exit_add
inf_neg_add:
or $v0, $v0, $k0
sw $v0, 32($t0)
j exit_add
pos_neg_add:
ori $v0, $0, 0x7f80
sll $v0, $v0, 16
sub $at, $at, $at
ori $at, $0, 0x1000
srl $at, $at,12
add $v0, $v0, $at #0x7f800001
sw $v0, 32($t0)
j exit_add
zero_1_add:
add $v0, $0, $s1
sw $v0, 32($t0)
j exit_add
zero_2_add:
add $v0, $0, $s0
sw $v0, 32($t0)
j exit_add
go_back_add:
jr $ra
premature_exit_add:
sub $s7, $t2, $t6
bne $s7, $0, go_back_add
bne $v1, $0, go_back_add
sub $v0, $v0, $v0
sw $v0, 32($t0)
j exit_add
exit_add:
jal reboot
j f_sub
reboot:
sub $v0, $v0, $v0
sub $v1, $v1, $v1
sub $a0, $a0, $a0
sub $a1, $a1, $a1
sub $a2, $a2, $a2
sub $a3, $a3, $a3
sub $t1, $t1, $t1
sub $t2, $t2, $t2
sub $t3, $t3, $t3
sub $t4, $t4, $t4
sub $t5, $t5, $t5
sub $t6, $t6, $t6
sub $t7, $t7, $t7
sub $t8, $t8, $t8
sub $t9, $t9, $t9
sub $s2, $s2, $s2
sub $s3, $s3, $s3
sub $s4, $s4, $s4
sub $s5, $s5, $s5
sub $s6, $s6, $s6
sub $s7, $s7, $s7
sub $k0, $k0, $k0
sub $k1, $k1, $k1
jr $ra
f_sub:
beq $s0, $0, zero_1_sub
beq $s1, $0, zero_2_sub
jal infinity_checker_sub
srl $t1, $s0, 31 #sign
sll $t1, $t1, 31
sll $t2, $s0, 1
srl $t2, $t2, 24 #exponent
addi $t2, $t2, -127 #remove bias
sll $t3, $s0, 9
srl $t3, $t3, 9 #mantissa
lui $t4, 0x0080
add $t3, $t3, $t4 #mantissa with implied 1
posA_sub:
beq $t5, $0, posAB_sub #A and B are positive
j mixedAB_1_sub #A is positive, B is negative
posB_sub:
beq $t1, $0, posAB_sub #A and B are positive
j mixedAB_2_sub #A is negative, B is positive
posAB_sub:
slt $a0, $t6, $t2
beq $a0, $0, posAB_sitB_sub
j posAB_sitA_sub
posAB_sitA_sub:
sub $t8,$t2,$t6
srlv $t7,$t7,$t8
nor $t7, $t7, $0
addi $t7, $t7, 0x00000001 #2s complement
sub $at, $at, $at
ori $at,$0,0x100
sll $at, $at, 16 #sign bit
or $t7, $t7, $at
sll $t7, $t7, 7
srl $t7, $t7, 7
add $v0,$t7,$t3
sll $v0, $v0, 7
srl $v0, $v0, 7
sll $a3,$v0,7
srl $a3,$a3,31
sll $a3,$a3,31 #final sign
beq $a3,$0, no_complementA_sub
nor $v0, $v0, $0
addi $v0, $v0, 0x00000001
sll $v0, $v0, 7
srl $v0, $v0, 7
add $v1,$v0,$0
beq $v1, $0, premature_exit_sub
jal normalize
addi $a2, $a1, -24
bltz $a2, no_compfinalA_sub
srlv $v0, $v0, $a2 #normalize mantissa
sll $v0, $v0, 9
srl $v0, $v0, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t2, $t2, $a1
addi $t2, $t2, 127
sll $t2, $t2, 23 #final exponent
add $v0, $v0, $t2
add $v0, $v0, $a3 #final sign
sw $v0, 36($t0)
j exit_sub
posAB_sitB_sub:
sub $t9,$t6,$t2
srlv $t3,$t3,$t9
nor $t7, $t7, $0
addi $t7, $t7, 0x00000001 #2s complement
sub $at, $at, $at
ori $at,$0,0x100
sll $at, $at, 16 #sign bit
or $t7, $t7, $at
sll $t7, $t7, 7
srl $t7, $t7, 7
add $v0,$t3,$t7
sll $v0, $v0, 7
srl $v0, $v0, 7
sll $a3,$v0,7
srl $a3,$a3,31
sll $a3,$a3,31 #final sign
beq $a3,$0, no_complementB_sub
nor $v0, $v0, $0
addi $v0, $v0, 0x00000001
sll $v0, $v0, 7
srl $v0, $v0, 7
add $v1,$v0,$0
beq $v1, $0, premature_exit_sub
jal normalize
addi $a2, $a1, -24
bltz $a2, no_compfinalB_sub
srlv $v0, $v0, $a2 #normalize mantissa
sll $v0, $v0, 9
srl $v0, $v0, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t6, $t6, $a1
addi $t6, $t6, 127
sll $t6, $t6, 23 #final exponent
add $v0, $v0, $t6
add $v0, $v0, $a3
sw $v0, 36($t0)
j exit_sub
negAB_sub:
slt $a0, $t6, $t2
beq $a0, $0, negAB_sitB_sub
j negAB_sitA_sub
negAB_sitA_sub:
sub $t8,$t2,$t6
srlv $t7,$t7,$t8
nor $t3, $t3, $0
addi $t3, $t3, 0x00000001 #2s complement for negative (A)
sub $at, $at, $at
ori $at,$0,0x100
sll $at, $at, 16 #sign bit
or $t3, $t3, $at
sll $t3, $t3, 7
srl $t3, $t3, 7
nor $t7, $t7, $0
addi $t7, $t7, 0x00000001 #2s complement for negative (B)
sub $at, $at, $at
ori $at,$0,0x100
sll $at, $at, 16 #sign bit
or $t7, $t7, $at
sll $t7, $t7, 7
srl $t7, $t7, 7
nor $t7, $t7, $0
addi $t7, $t7, 0x00000001 #2s complement for subtraction (B)
sll $t7, $t7, 7
srl $t7, $t7, 7
add $v0,$t7,$t3
sll $v0, $v0, 7
srl $v0, $v0, 7
sll $a3,$v0,7
srl $a3,$a3,31
sll $a3,$a3,31 #final sign
beq $a3,$0, no_complementA_sub
nor $v0, $v0, $0
addi $v0, $v0, 0x00000001
sll $v0, $v0, 7
srl $v0, $v0, 7
add $v1,$v0,$0
beq $v1, $0, premature_exit_sub
jal normalize
addi $a2, $a1, -24
bltz $a2, no_compfinalA_sub
srlv $v0, $v0, $a2 #normalize mantissa
sll $v0, $v0, 9
srl $v0, $v0, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t2, $t2, $a1
addi $t2, $t2, 127
sll $t2, $t2, 23 #final exponent
add $v0, $v0, $t2
add $v0, $v0, $a3 #final sign
sw $v0, 36($t0)
j exit_sub
negAB_sitB_sub:
sub $t9,$t6,$t2
srlv $t3,$t3,$t9
nor $t3, $t3, $0
addi $t3, $t3, 0x00000001 #2s complement for negative (A)
sub $at, $at, $at
ori $at,$0,0x100
sll $at, $at, 16 #sign bit
or $t3, $t3, $at
sll $t3, $t3, 7
srl $t3, $t3, 7
nor $t7, $t7, $0
addi $t7, $t7, 0x00000001 #2s complement for negative (B)
sub $at, $at, $at
ori $at,$0,0x100
sll $at, $at, 16 #sign bit
or $t7, $t7, $at
sll $t7, $t7, 7
srl $t7, $t7, 7
nor $t7, $t7, $0
addi $t7, $t7, 0x00000001 #2s complement for subtraction (B)
sll $t7, $t7, 7
srl $t7, $t7, 7
add $v0,$t3,$t7
sll $v0, $v0, 7
srl $v0, $v0, 7
sll $a3,$v0,7
srl $a3,$a3,31
sll $a3,$a3,31 #final sign
beq $a3,$0, no_complementB_sub
nor $v0, $v0, $0
addi $v0, $v0, 0x00000001
sll $v0, $v0, 7
srl $v0, $v0, 7
add $v1,$v0,$0
beq $v1, $0, premature_exit_sub
jal normalize
addi $a2, $a1, -24
bltz $a2, no_compfinalB_sub
srlv $v0, $v0, $a2 #normalize mantissa
sll $v0, $v0, 9
srl $v0, $v0, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t6, $t6, $a1
addi $t6, $t6, 127
sll $t6, $t6, 23 #final exponent
add $v0, $v0, $t6
add $v0, $v0, $a3
sw $v0, 36($t0)
j exit_sub
mixedAB_1_sub:
slt $a0, $t6, $t2
beq $a0, $0, mixedAB1_sitB_sub
j mixedAB1_sitA_sub
mixedAB1_sitA_sub:
sub $t8,$t2,$t6
srlv $t7,$t7,$t8
nor $t7, $t7, $0
addi $t7, $t7, 0x00000001 #2s complement for negative (B)
sll $t7, $t7, 7
srl $t7, $t7, 7
nor $t7, $t7, $0
addi $t7, $t7, 0x00000001 #2s complement for subtraction (B)
sll $t7, $t7, 7
srl $t7, $t7, 7
add $v0,$t7,$t3
add $v1,$v0,$0
beq $v1, $0, premature_exit_sub
jal normalize
addi $a2, $a1, -24
srlv $v0, $v0, $a2 #normalize mantissa
sll $v0, $v0, 9
srl $v0, $v0, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t2, $t2, $a1
addi $t2, $t2, 127
sll $t2, $t2, 23 #final exponent
add $v0, $v0, $t2
add $v0, $v0, $a3 #final sign
sw $v0, 36($t0)
j exit_sub
mixedAB1_sitB_sub:
sub $t9,$t6,$t2
srlv $t3,$t3,$t9
nor $t7, $t7, $0
addi $t7, $t7, 0x00000001 #2s complement for negative (B)
sub $at, $at, $at
ori $at,$0,0x100
sll $at, $at, 16 #sign bit
or $t7, $t7, $at
sll $t7, $t7, 7
srl $t7, $t7, 7
nor $t7, $t7, $0
addi $t7, $t7, 0x00000001 #2s complement for subtraction (B)
sll $t7, $t7, 7
srl $t7, $t7, 7
add $v0,$t3,$t7
sll $v0, $v0, 7
srl $v0, $v0, 7
sll $a3,$v0,7
srl $a3,$a3,31
sll $a3,$a3,31 #final sign
beq $a3,$0, no_complementB_sub
nor $v0, $v0, $0
addi $v0, $v0, 0x00000001
sll $v0, $v0, 7
srl $v0, $v0, 7
add $v1,$v0,$0
beq $v1, $0, premature_exit_sub
jal normalize
addi $a2, $a1, -24
bltz $a2, no_compfinalB_sub
srlv $v0, $v0, $a2 #normalize mantissa
sll $v0, $v0, 9
srl $v0, $v0, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t6, $t6, $a1
addi $t6, $t6, 127
sll $t6, $t6, 23 #final exponent
add $v0, $v0, $t6
add $v0, $v0, $a3
sw $v0, 36($t0)
j exit_sub
mixedAB_2_sub:
slt $a0, $t6, $t2
beq $a0, $0, mixedAB2_sitB_sub
j mixedAB2_sitA_sub
mixedAB2_sitA_sub:
sub $t8,$t2,$t6
srlv $t7,$t7,$t8
nor $t3, $t3, $0
addi $t3, $t3, 0x00000001 #2s complement for negative (B)
sub $at, $at, $at
ori $at,$0,0x100
sll $at, $at, 16 #sign bit
or $t3, $t3, $at
sll $t3, $t3, 7
srl $t3, $t3, 7
nor $t7, $t7, $0
addi $t7, $t7, 0x00000001 #2s complement for subtraction (B)
sll $t7, $t7, 7
srl $t7, $t7, 7
add $v0,$t7,$t3
sll $v0, $v0, 7
srl $v0, $v0, 7
sll $a3,$v0,7
srl $a3,$a3,31
sll $a3,$a3,31 #final sign
beq $a3,$0, no_complementA_sub
nor $v0, $v0, $0
addi $v0, $v0, 0x00000001
sll $v0, $v0, 7
srl $v0, $v0, 7
add $v1,$v0,$0
beq $v1, $0, premature_exit_sub
jal normalize
addi $a2, $a1, -24
bltz $a2, no_compfinalA_sub
srlv $v0, $v0, $a2 #normalize mantissa
sll $v0, $v0, 9
srl $v0, $v0, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t2, $t2, $a1
addi $t2, $t2, 127
sll $t2, $t2, 23 #final exponent
add $v0, $v0, $t2
add $v0, $v0, $a3 #final sign
sw $v0, 36($t0)
j exit_sub
mixedAB2_sitB_sub:
sub $t9,$t6,$t2
srlv $t3,$t3,$t9
nor $t3, $t3, $0
addi $t3, $t3, 0x00000001 #2s complement for negative (B)
sub $at, $at, $at
ori $at,$0,0x100
sll $at, $at, 16 #sign bit
or $t3, $t3, $at
sll $t3, $t3, 7
srl $t3, $t3, 7
nor $t7, $t7, $0
addi $t7, $t7, 0x00000001 #2s complement for subtraction (B)
sll $t7, $t7, 7
srl $t7, $t7, 7
add $v0,$t3,$t7
sll $v0, $v0, 7
srl $v0, $v0, 7
sll $a3,$v0,7
srl $a3,$a3,31
sll $a3,$a3,31 #final sign
beq $a3,$0, no_complementB_sub
nor $v0, $v0, $0
addi $v0, $v0, 0x00000001
sll $v0, $v0, 7
srl $v0, $v0, 7
add $v1,$v0,$0
beq $v1, $0, premature_exit_sub
jal normalize
addi $a2, $a1, -24
bltz $a2, no_compfinalB_sub
srlv $v0, $v0, $a2 #normalize mantissa
sll $v0, $v0, 9
srl $v0, $v0, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t6, $t6, $a1
addi $t6, $t6, 127
sll $t6, $t6, 23 #final exponent
add $v0, $v0, $t6
add $v0, $v0, $a3
sw $v0, 36($t0)
j exit_sub
normalize:
beq $v1, $0, go_back_sub
addi $a1, $a1, 1
srl $v1, $v1, 1
j normalize
no_complementA_sub:
add $v1,$v0,$0
beq $v1, $0, premature_exit_sub
jal normalize
addi $a2, $a1, -24
bltz $a2, no_compfinalA_sub
srlv $v0, $v0, $a2 #normalize mantissa
sll $v0, $v0, 9
srl $v0, $v0, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t2, $t2, $a1
addi $t2, $t2, 127
sll $t2, $t2, 23 #final exponent
add $v0, $v0, $t2
add $v0, $v0, $a3 #final sign
sw $v0, 36($t0)
j exit_sub
no_compfinalA_sub:
sub $a2, $0, $a2
sllv $v0, $v0, $a2 #normalize mantissa
sll $v0, $v0, 9
srl $v0, $v0, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t2, $t2, $a1
addi $t2, $t2, 127
sll $t2, $t2, 23 #final exponent
add $v0, $v0, $t2
add $v0, $v0, $a3 #final sign
sw $v0, 36($t0)
j exit_sub
no_complementB_sub:
add $v1,$v0,$0
beq $v1, $0, premature_exit_sub
jal normalize
addi $a2, $a1, -24
bltz $a2, no_compfinalB_sub
srlv $v0, $v0, $a2 #normalize mantissa
sll $v0, $v0, 9
srl $v0, $v0, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t6, $t6, $a1
addi $t6, $t6, 127
sll $t6, $t6, 23 #final exponent
add $v0, $v0, $t6
add $v0, $v0, $a3
sw $v0, 36($t0)
j exit_sub
no_compfinalB_sub:
sub $a2, $0, $a2
sllv $v0, $v0, $a2 #normalize mantissa
sll $v0, $v0, 9
srl $v0, $v0, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t6, $t6, $a1
addi $t6, $t6, 127
sll $t6, $t6, 23 #final exponent
add $v0, $v0, $t6
add $v0, $v0, $a3 #final sign
sw $v0, 36($t0)
j exit_sub
infinity_checker_sub:
ori $k0,$0,0xff80
sll $k0, $k0, 16
ori $k1, $0, 0x7f80
sll $k1, $k1, 16
beq $s0, $k0, inf3_sub
beq $s0, $k1, inf4_sub
beq $s1, $k0, inf1_sub
beq $s1, $k1, inf2_sub
j go_back_sub
inf1_sub:
beq $s1, $k0, inf_pos_sub
j inf_neg_sub
inf2_sub:
beq $s1, $k1, inf_neg_sub
j inf_pos_sub
inf3_sub:
beq $s1, $k0, pos_neg_sub
beq $s1, $k1, inf_neg_sub
j inf_neg_sub
inf4_sub:
beq $s1, $k0, inf_pos_sub
beq $s1, $k1, pos_neg_sub
j inf_pos_sub
inf_pos_sub:
or $v0, $v0, $k1
sw $v0, 36($t0)
j exit_sub
inf_neg_sub:
or $v0, $v0, $k0
sw $v0, 36($t0)
j exit_sub
pos_neg_sub:
ori $v0, $0, 0x7f80
sll $v0, $v0, 16
sub $at, $at, $at
ori $at, $0, 0x1000
srl $at, $at,12
add $v0, $v0, $at #0x7f800001
sw $v0, 36($t0)
j exit_sub
zero_1_sub:
add $v0, $0, $s1
sub $at, $at, $at
srl $at, $v0, 31
beq $at, $0, zero_1_sub_neg
sll $v0, $v0, 1
srl $v0, $v0, 1
sw $v0, 36($t0)
j exit_sub
zero_1_sub_neg:
sub $at, $at, $at
ori $at,$0,0x8000
sll $at, $at, 16 #sign bit
or $v0, $v0, $at
sw $v0, 36($t0)
j exit_sub
zero_2_sub:
add $v0, $0, $s0
sw $v0, 36($t0)
j exit_sub
go_back_sub:
jr $ra
premature_exit_sub:
sub $v0, $v0, $v0
sw $v0, 36($t0)
j exit_sub
exit_sub:
jal reboot
j f_mult
f_mult:
beq $s0, $0, multzero_mult
beq $s1, $0, multzero_mult
jal infinity_checker_mult
srl $t1, $s0, 31 #sign
sll $t1, $t1, 31
sll $t2, $s0, 1
srl $t2, $t2, 24 #exponent
addi $t2, $t2, -127 #remove bias
sll $t3, $s0, 9
srl $t3, $t3, 9 #mantissa
lui $t4, 0x0080
add $t3, $t3, $t4 #mantissa with implied 1 (A)
jal expchecker2
loop_mult:
beq $s6, $0, exitmult
jal LSBchecker_mult
srl $s2,$s2,1
srl $s3,$s3,1
addi $s6, $s6, -1
j loop_mult
LSBchecker_mult:
sll $s4,$s3, 31
srl $s4,$s4, 31 #LSB of B
beq $s4, $0, toB_mult
j toA_mult
toB_mult:
add $s2, $0, $s2 #A = A+0
add $s3, $0, $s3 #B = B+0
j back_mult
toA_mult:
add $s2, $t3, $s2 #load A
add $s3, $0, $s3
j back_mult
back_mult:
jr $ra
exitmult:
beq $t1, $t5, posi_mult #(+ x +) && (- x -) == +
sub $at, $at, $at
ori $at,$0,0x8000
sll $at, $at, 16
or $v0, $v0, $at #(- x +) && (+ x -) == -
add $t2, $t2, $t6 #add exponents of A and B (both already without
biases)
addi $t2, $t2, 127
jal checker2
#shifting and combining A and B first
sll $s2, $s2, 8
sll $s3, $s3, 8
srl $s3, $s3, 24
or $s5, $s2, $s3 #semi-final mantissa
srl $s5, $s5, 9
add $v1,$s5,$0
jal normalize
addi $a2, $a1, -24
bltz $a2, no_compfinalmult_mult
srlv $s5, $s5, $a2 #close final mantissa
sll $s5, $s5, 9
srl $s5, $s5, 9 #final mantissa
addi $a1, $a1, -24 #to be added to exponent
add $t2, $t2, $a1
sll $t2, $t2, 23 #final exponent
add $v0, $v0, $t2
add $v0, $v0, $s5
sw $v0, 40($t0)
j byemult_mult
posi_mult:
andi $v0, $0, 0x00000000
add $t2, $t2, $t6 #add exponents of A and B (both already without
biases)
addi $t2, $t2, 127
jal checker1
#shifting and combining A and B first
sll $s2, $s2, 8
sll $s3, $s3, 8
srl $s3, $s3, 24
or $s5, $s2, $s3 #semi-final mantissa
srl $s5, $s5, 9
add $v1,$s5,$0
jal normalize
addi $a2, $a1, -24
bltz $a2, no_compfinalmult_mult
srlv $s5, $s5, $a2 #close final mantissa
sll $s5, $s5, 9
srl $s5, $s5, 9 #final mantissa
sll $t2, $t2, 23 #final exponent
add $v0, $v0, $t2
add $v0, $v0, $s5
sw $v0, 40($t0)
j byemult_mult
infinity_checker_mult:
ori $k0, $0, 0x7f80
sll $k0, $k0, 16
ori $k1,$0,0xff80
sll $k1, $k1, 16
beq $s0, $k0, multinf1
beq $s0, $k1, multinf2
beq $s1, $k0, multinf3
beq $s1, $k1, multinf4
j back_mult
multinf1:
beq $s1, $k0, posinf_mult
beq $s1, $k1, neginf_mult
sub $at, $at, $at
srl $at, $s1, 31
beq $at, $0, posinf_mult
j neginf_mult
multinf2:
beq $s1, $k0, neginf_mult
beq $s1, $k1, posinf_mult
sub $at, $at, $at
srl $at, $s1, 31
beq $at, $0, neginf_mult
j posinf_mult
multinf3:
beq $s0, $k0, posinf_mult
beq $s0, $k1, neginf_mult
sub $at, $at, $at
srl $at, $s0, 31
beq $at, $0, posinf_mult
j neginf_mult
multinf4:
beq $s0, $k0, neginf_mult
beq $s0, $k1, posinf_mult
sub $at, $at, $at
srl $at, $s0, 31
beq $at, $0, neginf_mult
j posinf_mult
posinf_mult:
add $v0, $0, $k0
sw $v0, 40($t0)
j byemult_mult
neginf_mult:
add $v0, $0, $k1
sw $v0, 40($t0)
j byemult_mult
no_compfinalmult_mult:
sub $a2, $0, $a2
jal checker
add $t2, $a2, $t2
sllv $s5, $s5, $a2 #close final mantissa
sll $s5, $s5, 9
srl $s5, $s5, 9 #final mantissa
sll $t2, $t2, 23 #final exponent
add $v0, $v0, $t2
add $v0, $v0, $s5
sw $v0, 40($t0)
j byemult_mult
multzero_mult:
add $v0, $0, $0
sw $v0, 40($t0)
j byemult_mult
expchecker2:
beq $t2, $0, increm2
j back_mult
expchecker6:
beq $t6, $0, increm2
j back_mult
increm2:
addi $t2, $0, 1
j back_mult
increm6:
addi $t6, $0, 1
j back_mult
checker:
addi $s7, $0, 2
bne $a2, $s7, back_mult
sllv $s5, $s5, $a2 #close final mantissa
sll $s5, $s5, 9
srl $s5, $s5, 9 #final mantissa
sll $t2, $t2, 23 #final exponent
add $v0, $v0, $t2
add $v0, $v0, $s5
sw $v0, 40($t0)
j byemult_mult
checker1:
addi $s7, $0, 255
sub $at, $at, $at
slt $at, $t2, $s7
beq $at, $0, posinf_mult
j back_mult
checker2:
addi $s7, $0, 255
sub $at, $at, $at
slt $at, $t2, $s7
beq $at, $0, neginf_mult
j back_mult
byemult_mult:
jal reboot
j f_div
f_div:
jal infinitydiv_div
beq $s0, $0, div0_div
beq $s1, $0, div1_div
srl $t1, $s0, 31 #sign
sll $t1, $t1, 31
sll $t2, $s0, 1
srl $t2, $t2, 24 #exponent
addi $t2, $t2, -127 #remove bias
sll $t3, $s0, 9
srl $t3, $t3, 9 #mantissa
lui $t4, 0x0080
add $t3, $t3, $t4 #mantissa with implied 1 (A)
loop_div:
beq $s6, $0, zerodiv_div
sll $a3, $s3, 8
srl $a3, $a3, 31
sll $s4,$s7, 7
srl $s4,$s4, 31 #MSB of B
sll $s3, $s3, 1
sll $s7, $s7, 1
add $s7, $s7, $a3
jal step_div
jal sign_div
addi $s6, $s6, -1
j loop_div
step_div:
beq $s4, $0, stepsub_div
add $s7, $s7, $t7
j back_div
stepsub_div:
add $s7, $s7, $s5
j back_div
sign_div:
beq $s4, $0, signsub_div
addi $s3, $s3, 0x00000000
j back_div
signsub_div:
addi $s3, $s3, 0x00000001
j back_div
zerodiv_div:
sll $s4,$s7, 31
srl $s4,$s7, 31 #MSB of B
j zerosign_div
zerosign_div:
beq $s4, $0, exitdiv_div
add $s7, $s7, $t7
j exitdiv_div
exitdiv_div:
beq $t1, $t5, posdiv_div #(+ x +) && (- x -) == +
sub $at, $at, $at
ori $at,$0,0x8000
sll $at, $at, 16
or $v0, $v0, $at #(- x +) && (+ x -) == -
sub $t2, $t2, $t6 #add exponents of A and B (both already without
biases)
addi $t2, $t2, 127 #x-y + 127
sll $s7, $s7, 9
srl $s7, $s7, 9 #final mantissa
add $v1,$s7,$0
jal normalize
no_compfinaldiv_div:
sub $a2, $0, $a2
sllv $s7, $s7, $a2 #close final mantissa
sll $s7, $s7, 9
srl $s7, $s7, 9 #final mantissa
sll $t2, $t2, 23 #final exponent
add $v0, $v0, $t2
add $v0, $v0, $s7
sw $v0, 44($t0)
j byediv_div
posdiv_div:
andi $v0, $0, 0x00000000
sub $t2, $t2, $t6 #add exponents of A and B (both already without
biases)
addi $t2, $t2, 127 #x-y + 127
sll $s7, $s7, 9
srl $s7, $s7, 9 #final mantissa
add $v1,$s7,$0
jal normalize
infinitydiv_div:
ori $k0,$0,0x7f80
sll $k0, $k0, 16
ori $k1,$0,0xff80
sll $k1, $k1, 16
beq $s0, $k0, divinf1_div
beq $s0, $k1, divinf2_div
beq $s1, $k0, divinf3_div
beq $s1, $k1, divinf4_div
j back_div
divinf1_div:
beq $s1, $0, nandiv_div
beq $s1, $k0, nandiv_div
beq $s1, $k1, nandiv_div
j posinf_div
divinf2_div:
beq $s1, $0, nandiv_div
beq $s1, $k0, nandiv_div
beq $s1, $k1, nandiv_div
j neginf_div
divinf3_div:
beq $s0, $k0, nandiv_div
beq $s0, $k1, nandiv_div
j posinf_div
divinf4_div:
beq $s0, $k0, nandiv_div
beq $s0, $k1, nandiv_div
j neginf_div
nandiv_div:
ori $v0, $0, 0x7f80
sll $v0, $v0, 16
sub $at, $at, $at
ori $at, $0, 0x1000
srl $at, $at,12
add $v0, $v0, $at #0x7f800001
sw $v0, 44($t0)
j byediv_div
posinf_div:
add $v0, $0, $k0
sw $v0, 44($t0)
j byediv_div
neginf_div:
add $v0, $0, $k1
sw $v0, 44($t0)
j byediv_div
div0_div:
beq $s1, $0, div1_div
sub $v0, $v0, $v0
sw $v0, 44($t0)
j byediv_div
div1_div:
ori $v0, $0, 0x7f80
sll $v0, $v0, 16
sub $at, $at, $at
ori $at, $0, 0x1000
srl $at, $at,12
add $v0, $v0, $at #0x7f800001
sw $v0, 44($t0)
j byediv_div
back_div:
jr $ra
byediv_div:
jal reboot
j final_exit
final_exit: