---
# System prepended metadata

title: Lab x

---

# Lab 7
Name: Lavkush Kumar
Roll No.: CS22B034

---
## Question 1

**(0.1)<sub>10</sub> to binary.** 

0.1 × 2 = 0 + 0.2
0.2 × 2 = 0 + 0.4
0.4 × 2 = 0 + 0.8
0.8 × 2 = 1 + 0.6
0.6 × 2 = 1 + 0.2
0.2 × 2 = 0 + 0.4
0.4 × 2 = 0 + 0.8
0.8 × 2 = 1 + 0.6
0.6 × 2 = 1 + 0.2
0.2 × 2 = 0 + 0.4


**Observation:** 
* Take integer part for binary so, binary for 0.1 is **0.0001 1001 1001 1001 1001 1001 100.....**
---
## Question 2
**(0.1)<sub>10</sub> to binary using IEEE 754 standard.** 

(0.1)<sub>10</sub> = 0.0001 1001 1001 1001 1001 1001 100<sub>(2)</sub> 
Shift the decimal mark 4 positions to the right, so that only one non zero digit remains to the left of it
(0.1)<sub>10</sub> = 0.0001 1001 1001 1001 1001 1001 100<sub>(2)</sub> × 2<sup>0</sup>
(0.1)<sub>10</sub> = 1.1001 1001 1001 1001 1001 100<sub>(2) </sub>× 2<sup>-4</sup>

there are the following elements that would feed into the 32 bit single precision IEEE 754 binary floating point representation:

* Sign 0 (a positive number)
* Exponent (unadjusted) : -4
    * Exponent (adjusted) =Exponent (unadjusted) + 2<sup>(8-1)</sup> - 1 = -4 + 2<sup>(8-1)</sup> - 1 =(-4 + 127)<sub>(10)</sub> = 123<sub>(10)</sub>
    * 123<sub>(10)</sub> = 0111 1011<sub>(2)</sub>

* Mantissa (normalized) : 1001 1001 1001 1001 1001 100

**The base ten decimal number 0.1 converted and written in 32 bit single precision IEEE 754 binary floating point representation:
0 - 0111 1011 - 100 1100 1100 1100 1100 110**

---
## Question 3
**(0.2)<sub>10</sub> to binary using IEEE 754 standard.** 

(0.2)<sub>10</sub> = 0.0011 0011 0011 0011 0011 0011 00<sub>(2)</sub> 
Shift the decimal mark 4 positions to the right, so that only one non zero digit remains to the left of it
(0.2)<sub>10</sub> =0.0011 0011 0011 0011 0011 0011 00<sub>(2)</sub> × 2<sup>0</sup>
(0.2)<sub>10</sub> = 1.1001 1001 1001 1001 1001 100<sub>(2) </sub>× 2<sup>-3</sup>

there are the following elements that would feed into the 32 bit single precision IEEE 754 binary floating point representation:

* Sign 0 (a positive number)
* Exponent (unadjusted) : -3
    * Exponent (adjusted) =Exponent (unadjusted) + 2<sup>(8-1)</sup> - 1 = -3 + 2<sup>(8-1)</sup> - 1 =(-3 + 127)<sub>(10)</sub> = 124<sub>(10)</sub>
    * 124<sub>(10)</sub> = 0111 1100<sub>(2)</sub>

* Mantissa (normalized) : 100 1100 1100 1100 1100 1100

**The base ten decimal number 0.1 converted and written in 32 bit single precision IEEE 754 binary floating point representation:
0 - 0111 1100 - 100 1100 1100 1100 1100 1100**


**(0.2)<sub>10</sub>  IEEE 754 standard to Decimal.** 

* Sign 0 (a positive number)
* Exponential bits is 0111 1100 and in decimal is 124 but we have exponential bias is 127 so exponential(e) = 127-124 = 3
* Mantissa bits is 100 1100 1100 1100 1100 1100 and in decimal is 0.5999999046325684
* Now put the decimal value of sign bit,exponential bits and matissa bits (-1)<sup>sign</sup> x (1+mantissa) x 2<sup>e</sup>
* Value actually stored in float : 0.199999988079071044921875
*  **Decimal Representation : 0.19999999**
---

## Question 4
Sign Bit: 1 bit to represent the sign of the number (positive or negative).
Integer Part: 16 bits to represent the integer part of the number.
Fractional Part: 16 bits to represent the fractional part of the number.
 Comment
For addition, we'll perform addition separately on the integer parts and fractional parts, taking care of any carry from the fractional part to the integer part.

as per given example:
5.391 = 5 + 0.391
5 = 00000000000000101
0.391 = 0110010000011000

3.012 = 3 + 0.012
3 = 00000000000000011
0.012 = 0000001100010010

0.391 + 0.012 = 0110011100111010
carry = 0

5 + 3 + carry = 00000000000001000
Final sum: 00000000000001000.0110011100111010

---
## Question 5
```assembly=
#Assume the two floating-point numbers are stored in memory in addresses num1 and num2
# Assume the result will be stored in memory at address result_ptr

# Load the first floating-point number into a floating-point register (f0)
lw f0, 0(num1)

# Load the second floating-point number into a different floating-point register (f1)
lw f1, 0(num2)

# Add the two floating-point numbers
fadd.s f2, f0, f1

# Store the result back into memory
sw f2, 0(result)
```
