Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- .data
- newline: .ascii "\n"
- Input_Message: .asciiz "\nPlease Enter a floating-point number: "
- Second_Input_Message: .asciiz "\nPlease enter a second floating-point number: "
- Answer: .asciiz "The sum of the two floating point values is: "
- .text
- main:
- li $v0, 4
- la $a0,Input_Message
- syscall #syscall to print out the input message
- li $v0,6
- syscall #syscall to read a float input from the user
- mfc1 $t0,$f0 #moves the float value from coprocessor to register
- add $a1, $t0, $zero #stores the float value into register $a1
- li $v0, 4
- la $a0,Second_Input_Message
- syscall #syscall to print out the second input message
- li $v0,6
- syscall # reads a float value from the user
- mfc1 $t1,$f0 #moves the float value from coprocessor to register
- add $a2, $t1, $zero #stores that value into $a2
- bgtz $a1,exponent #if $a1 is greater than zero, branch to exponent
- bgtz $a2,exponent #if $a2 is greater than zero, branch to exponent
- exponent:
- move $s0,$a1 #loads $a1 into $s0
- sll $s5,$s0,1 #shifts $s0 to the left by 1 and store into register $s5
- srl $s5,$s5,24 #shift $s5 right by 24 and store into $s5
- move $s1,$a2 #moves the second exponent into register $s1
- sll $s6,$s1,1 #shifts $s1 left 1 and store into register $s6
- srl $s6,$s6,24 #shifts $s6 right 24 and store into same register
- srl $s3,$s0,31 #shift $s0 right 31 and store in $s3
- srl $s4,$s1,31 #shift value $s1 right 31 and store in $s4
- li $t9,1
- sll $t9,$t9,23 #shifts $t9 register left 23
- sll $s7,$s0,9 #shift $s0 left 9 and store value into $s7
- srl $s7,$s7,9 #shift $s7 right 9 and store into $s7
- or $s7,$s7,$t9
- sll $t8,$s1,9
- srl $t8,$t8,9
- or $t8,$t8,$t9
- Matching_Exponents: #loop which shifts the smaller exponent until it is the same as the larger exponent
- beq $s5,$s6, Calculations #if the exponents are equal, branch to Calculations
- blt $s5,$s6, shift_value_right #continue shifting until exponents are equal
- blt $s6,$s5, shift_secondvalue_right #continue shifting until exponents are equal
- j Matching_Exponents #loop until conditions are met to branch
- shift_value_right: #shifts the value right by 1 and loops until the exponents of the two values match
- srl $s7,$s7,1
- addi $s5,$s5,1
- j Matching_Exponents
- shift_secondvalue_right: #shifts the value right by 1 and loops until the exponents of the two values match
- srl $t8,$t8,1
- addi $s6,$s6,1
- j Matching_Exponents
- Calculations:
- beqz $s3,calc_one #if significand = 0 then branch
- sub $s7,$0,$s7
- calc_one:
- beqz $s4,calc_two #if second significand = 0 branch
- sub $t8,$0,$t8
- calc_two:
- add $t3,$s7,$t8
- li $s3,0
- bgez $t3, calc_three
- sub $t3,$0,$t3
- li $s3,1
- calc_three:
- clz $t2,$t3 #stores the number of leading zeros into $t
- blt $t2,8,Branch
- bgt $t2,8,Branch_Two
- j Normalize #loop
- Branch:
- srl $t3,$t3,1
- addi $s6,$s6,1
- j Normalize #loop
- Branch_Two:
- addi $t2,$t2,-8 #adds -8 to $t2
- sub $s6,$s6,$t2
- sllv $t3,$t3,$t2
- Normalize:
- xor $t3,$t3,$t9
- sll $t4,$s3,31 #shift s3 left 31 and store in $t4
- sll $t5,$s6,23 #shift s6 left 23 and store in $t5
- add $t6,$t4,$t5 #add the value of $t5 and $t6 and store in $t6
- add $t6,$t6,$t3 #add $t3 and $t6 and store in $t6
- li $v0, 4 #Prints the prompt defined in the data section Answer:
- la $a0,Answer
- syscall
- li $v0,2
- mtc1 $t6,$f12 #moves the register value $t6 into coprocessor $f10
- syscall
- exit:
Advertisement
Add Comment
Please, Sign In to add comment