Assignment 3 Answer (1) FINAL............. Coal
Assignment 3 Answer (1) FINAL............. Coal
Section: A7:
Azfar Amjad F2023376185
Basim Abrar F2023376177
Question 1. Analyze the value of the bit pattern 0x0C000000 if it represents a floating
Solution: 0x0C000000 = 0000 1100 0000 0000 0000 0000 0000 0000
Sign bit = 0
Exponent = 00011000 = 24
Mantissa = 00000000000000000000000 = 0
Value = 1 X 2-103
Sign bit = 0
exponent = 10000100 = 5
Sign bit = 1
exponent = 10001001 = 10
Question 4. Analyze the decimal value represented by the bit pattern 0xC1A40000 in
Solution: 0xC1A40000 = 1100 0001 1010 0100 0000 0000 0000 0000
Sign bit = 1
Question 5. Analyze the IEEE 754 single-precision binary representation for the
Sign bit = 0
Exponent =10000110 = 7
Mantissa = 11110101000000000000000 = 11110101
Question 6. Analyze the value of the IEEE 754 double-precision bit pattern
Solution: 0x4022000000000000 = 0100 0000 0010 0010 0000 0000 0000 0000 0000 0000 0000 0000
0000 0000 0000 0000
Sign bit= 0
Mantissa = 0010000000000000000000000000000000000000000000000000
Bias = 1023
Value = (-1)s X (1 + fraction) X (2)exponent – bias = (-1)0 X (1 + 0.125) X (2) 1026 – 1023
Question 7. Analyze how the IEEE 754 double-precision format encodes the decimal
Solution:
(3.14)10= (11.00100011110101110001)2
Exponent = 1
Sign Bit: 0
Mantissa = 100100011110101110001
Sign Bit: 0
Mantissa: 10010001111010111000
Mantissa=10000000000000000000000000000000
Solution:
Convert it to binary:
= (11111111100) - 1023
= 1021
1021-1023= -2
Mantissa value = 0.5
Value = (-1)s X (1 + fraction) X (2)exponent – bias = (-1)0 X (1 + 0.125) X (2) 1021 – 1023
= 1.5X2-2=0.375
Solution:
(-0.001953125)10= (0.000000001)2
= 1.000000000X2-9
Sign bit=1
Exponent = -9
Mantissa=000000000
Biased Exponent:
Mantissa = 00000000000000000000
numbers and branches accordingly (i.e., greater than, less than, and equal to).
Solution:
.data
.text
.globl main
main:
la $t0, num1
la $t1, num2
greater_than:
la $a0, gt
syscall
less_than:
la $a0, lt
syscall
equal:
la $a0, eq
syscall
end_program:
Question 11. Analyze a program that finds the maximum of two double-precision
Solution:
.data
.text
.globl main
main:
# If $f0 <= $f2, $f2 is the max. else $f0 is the max
storing_f0:
storing_f2:
result:
syscall
syscall
syscall
Question 12. Analyze a program that compares the absolute values of two single
Solution:
.data
.text
.globl main
main:
greater_abs_num2:
la $a0, num2gt
li $v0, 4
syscall
j exit
greater_abs_num1:
la $a0, num1gt
li $v0, 4
syscall
j exit
equal_abs:
# if abs(num1) == abs(num2)
la $a0, same
li $v0, 4
syscall
exit:
# Exit the program
li $v0, 10
syscall
Question 13. Analyze a program that finds how many single-precision floating-point
Solution:
.data
array: .float 4.8, 8.5, 6.0, 0.8, 5.0, 6.7, 2.3, 9.5, 3.9, 2.3
.text
.globl main
main:
skip:
end_l:
sw $t2, a
la $a0, r
li $v0, 4
syscall
li $v0, 1
syscall
li $v0, 10 # exiting the program
syscall