0% found this document useful (0 votes)
17 views9 pages

Floating Point Analysis MIPS Updated

The document provides a detailed analysis of floating-point number representations using IEEE 754 format, including conversions between hexadecimal, binary, and decimal for various numbers. It also includes MIPS assembly code examples for comparing and manipulating floating-point numbers, demonstrating how to find maximum values, compare absolute values, and count numbers above a threshold. Each section includes step-by-step calculations and expected outputs for clarity.

Uploaded by

mirzafarazmirza9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views9 pages

Floating Point Analysis MIPS Updated

The document provides a detailed analysis of floating-point number representations using IEEE 754 format, including conversions between hexadecimal, binary, and decimal for various numbers. It also includes MIPS assembly code examples for comparing and manipulating floating-point numbers, demonstrating how to find maximum values, compare absolute values, and count numbers above a threshold. Each section includes step-by-step calculations and expected outputs for clarity.

Uploaded by

mirzafarazmirza9
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 9

Floating-Point Number Analysis and MIPS Programs

Section I: IEEE 754 Analysis

Question 1:
Analyze the value of the bit pattern 0x0C000000 if it represents a floating-point number in
IEEE 754 single-precision format.

1. Convert the hexadecimal to binary: 0x0C000000 = 00001100 00000000 00000000


00000000.
2. Divide into IEEE 754 fields:
- Sign (1 bit): 0 (positive).
- Exponent (8 bits): 00001100 = 12 in decimal. Actual exponent = 12 - 127 = -115.
- Fraction (23 bits): All 0s = 0.
3. Value calculation:
(-1)^0 * (1 + 0) * 2^-115 = 2^-115 ≈ 3.45 x 10^-35 (very small positive number).

Question 2:
Analyze how the decimal number 63.25 is represented as a floating-point number in IEEE
754 single-precision format.

1. Convert 63.25 to binary:


- Integer part: 63 = 111111.
- Fractional part: 0.25 = 0.01 in binary.
- Combined binary: 111111.01.
2. Normalize: 1.1111101 x 2^5.
3. IEEE 754 fields:
- Sign: 0 (positive).
- Exponent: 5 + 127 = 132 = 10000100.
- Fraction: 1111101 (remaining bits padded with 0s to make 23 bits).
4. Final binary: 0 10000100 11111010000000000000000.
5. Convert to hexadecimal: 0x427E8000.

Question 3:
Analyze the floating-point representation of -1024.75 in IEEE 754 single-precision format.

1. Convert -1024.75 to binary:


- Integer part: 1024 = 10000000000.
- Fractional part: 0.75 = 0.11 in binary.
- Combined binary: 10000000000.11.
2. Normalize: 1.000000000011 x 2^10.
3. IEEE 754 fields:
- Sign: 1 (negative).
- Exponent: 10 + 127 = 137 = 10001001.
- Fraction: 00000000011 (remaining bits padded with 0s to make 23 bits).
4. Final binary: 1 10001001 00000000011000000000000.
5. Convert to hexadecimal: 0xC490C000.

Question 4:
Analyze the decimal value represented by the bit pattern 0xC1A40000 in IEEE 754 single-
precision format.

1. Convert hexadecimal to binary: 0xC1A40000 = 11000001 10100100 00000000


00000000.
2. Divide into IEEE 754 fields:
- Sign: 1 (negative).
- Exponent: 10000011 = 131 in decimal. Actual exponent = 131 - 127 = 4.
- Fraction: 10100100 00000000 00000000 = 1.101001.
3. Value calculation:
(-1)^1 * (1 + 0.101001) * 2^4 = -1.640625 * 16 = -26.25.

Question 5:
Analyze the IEEE 754 single-precision binary representation for the decimal number 250.5.

1. Convert 250.5 to binary:


- Integer part: 250 = 11111010.
- Fractional part: 0.5 = 0.1 in binary.
- Combined binary: 11111010.1.
2. Normalize: 1.11110101 x 2^7.
3. IEEE 754 fields:
- Sign: 0 (positive).
- Exponent: 7 + 127 = 134 = 10000110.
- Fraction: 11110101 (remaining bits padded with 0s to make 23 bits).
4. Final binary: 0 10000110 11110101000000000000000.
5. Convert to hexadecimal: 0x437A8000.
Question 6:
Analyze the value of the IEEE 754 double-precision bit pattern 0x4022000000000000.
What decimal number does it represent?

1. Convert hexadecimal to binary: 0x4022000000000000 = 01000000 00100010


00000000 00000000 00000000 00000000 00000000 00000000.
2. Divide into IEEE 754 fields:
- Sign: 0 (positive).
- Exponent: 10000000010 = 1026 in decimal. Actual exponent = 1026 - 1023 = 3.
- Fraction: 00001000000000000000000 (represents 1.25).
3. Value calculation:
(-1)^0 * (1 + 0.25) * 2^3 = 1.25 * 8 = 10.0.

Question 7:
Analyze how the IEEE 754 double-precision format encodes the decimal number 3.14.
Provide the bit pattern.

1. Convert 3.14 to binary:


- Integer part: 3 = 11.
- Fractional part: 0.14 ≈ 0.00100100001111 (rounded to 52 bits).
- Combined binary: 11.00100100001111.
2. Normalize: 1.100100100001111 x 2^1.
3. IEEE 754 fields:
- Sign: 0 (positive).
- Exponent: 1 + 1023 = 1024 = 10000000000.
- Fraction: 100100100001111 (padded to 52 bits).
4. Final binary: 0 10000000000
1001001000011110000000000000000000000000000000000000.
5. Convert to hexadecimal: 0x40091EB851EB851F.

Question 8:
Analyze how 0x3FD8000000000000 is represented in IEEE 754 double-precision format.
What decimal number does it correspond to?

1. Convert hexadecimal to binary: 0x3FD8000000000000 = 00111111 11011000


00000000 00000000 00000000 00000000 00000000 00000000.
2. Divide into IEEE 754 fields:
- Sign: 0 (positive).
- Exponent: 01111111101 = 1021 in decimal. Actual exponent = 1021 - 1023 = -2.
- Fraction: 11000000000000000000000 (represents 1.75).
3. Value calculation:
(-1)^0 * (1 + 0.75) * 2^-2 = 1.75 * 0.25 = 0.4375.

Question 9:
Analyze the IEEE 754 double-precision representation for -0.001953125. Provide both the
binary and hexadecimal representations.

1. Convert -0.001953125 to binary: 0.001953125 = 0.0000001 in binary.


2. Normalize: 1.0 x 2^-9.
3. IEEE 754 fields:
- Sign: 1 (negative).
- Exponent: -9 + 1023 = 1014 = 01111111010.
- Fraction: All 0s.
4. Final binary: 1 01111111010
0000000000000000000000000000000000000000000000000000.
5. Convert to hexadecimal: 0xBF20000000000000.

Section II: MIPS Floating-Point Programs

Question 10:
Refer to the provided MIPS program implementation and analysis for Question 10.

Question 11:
Refer to the provided MIPS program implementation and analysis for Question 11.

Question 12:
Refer to the provided MIPS program implementation and analysis for Question 12.

Question 13:
Refer to the provided MIPS program implementation and analysis for Question 13.

Question 10: Compare two single-precision floating-point numbers

MIPS Code:
```asm
.data
num1: .float 5.5 # First number
num2: .float 3.2 # Second number
greater_msg: .asciiz "Num1 is greater than Num2\n"
less_msg: .asciiz "Num1 is less than Num2\n"
equal_msg: .asciiz "Num1 is equal to Num2\n"

.text
.globl main
main:
# Load the two numbers
lwc1 $f0, num1 # Load num1 into $f0
lwc1 $f2, num2 # Load num2 into $f2

# Compare if num1 == num2


c.eq.s $f0, $f2 # Set condition flag if $f0 == $f2
bc1t equal_label # Branch to equal_label if true

# Compare if num1 < num2


c.lt.s $f0, $f2 # Set condition flag if $f0 < $f2
bc1t less_label # Branch to less_label if true

# If neither is true, num1 > num2


greater_label:
la $a0, greater_msg # Load address of greater_msg
li $v0, 4 # Print string syscall
syscall
j end # Jump to end

less_label:
la $a0, less_msg # Load address of less_msg
li $v0, 4 # Print string syscall
syscall
j end # Jump to end

equal_label:
la $a0, equal_msg # Load address of equal_msg
li $v0, 4 # Print string syscall
syscall

end:
li $v0, 10 # Exit syscall
syscall
```

**Expected Output**:
- If `num1 = 5.5` and `num2 = 3.2`, the output will be: "Num1 is greater than Num2".
- Modify `num1` and `num2` to test other conditions.
Question 11: Find the maximum of two double-precision floating-point numbers

MIPS Code:
```asm
.data
num1: .double 7.5 # First double-precision number
num2: .double 10.3 # Second double-precision number
max_result: .double 0.0 # To store the maximum value

.text
.globl main
main:
# Load the two numbers
ldc1 $f0, num1 # Load num1 into $f0-$f1
ldc1 $f2, num2 # Load num2 into $f2-$f3

# Compare if num1 <= num2


c.le.d $f0, $f2 # Set condition flag if $f0 <= $f2
bc1t second_is_max # Branch to second_is_max if true

# If num1 > num2


sdc1 $f0, max_result # Store num1 in max_result
j end # Jump to end

second_is_max:
sdc1 $f2, max_result # Store num2 in max_result

end:
li $v0, 10 # Exit syscall
syscall
```

**Expected Output**:
- For `num1 = 7.5` and `num2 = 10.3`, the value in `max_result` will be `10.3`. Change the
inputs to test other cases.

Question 12: Compare the absolute values of two single-precision floating-point numbers

MIPS Code:
```asm

.data
num1: .float -5.3 # First number
num2: .float 4.2 # Second number
greater_msg: .asciiz "Absolute value of Num1 is greater\n"
less_msg: .asciiz "Absolute value of Num1 is less\n"
equal_msg: .asciiz "Absolute values are equal\n"

.text
.globl main
main:
# Load the two numbers
lwc1 $f0, num1 # Load num1 into $f0
lwc1 $f2, num2 # Load num2 into $f2

# Calculate absolute values


abs.s $f0, $f0 # Absolute value of $f0
abs.s $f2, $f2 # Absolute value of $f2

# Compare absolute values


c.eq.s $f0, $f2 # Compare equality
bc1t equal_label

c.lt.s $f0, $f2 # Compare less than


bc1t less_label

greater_label:
la $a0, greater_msg # Load greater message
li $v0, 4 # Print string
syscall
j end

less_label:
la $a0, less_msg
li $v0, 4
syscall
j end

equal_label:
la $a0, equal_msg
li $v0, 4
syscall

end:
li $v0, 10 # Exit
syscall
```

**Expected Output**:
- Adjust array or threshold values to test the program's behavior.

Question 13: Count how many single-precision floating-point numbers in an array are greater
than a threshold of 3.0

MIPS Code:
```asm

.data
array: .float 1.2, 4.5, 2.9, 5.6, 3.1, 7.3, 2.5, 8.9, 1.1, 4.0
threshold: .float 3.0
count: .word 0

.text
.globl main
main:
# Initialize variables
la $t0, array # Load array address
li $t1, 10 # Array size
lwc1 $f2, threshold # Load threshold into $f2
li $t2, 0 # Counter for numbers greater than threshold

loop:
beq $t1, $zero, done # Exit loop if all elements are checked

# Load current array element


lwc1 $f0, 0($t0) # Load element into $f0
addiu $t0, $t0, 4 # Move to next element

# Compare with threshold


c.lt.s $f2, $f0 # Check if $f0 > $f2
bc1f skip_increment # Skip if false

addiu $t2, $t2, 1 # Increment counter

skip_increment:
addiu $t1, $t1, -1 # Decrement array size
j loop
done:
sw $t2, count # Store result in count
li $v0, 10 # Exit syscall
syscall

```

**Expected Output**:
- Adjust array or threshold values to test the program's behavior.

You might also like