# Lab 7
Name: Guru Rohith.G
Roll No.: CS22B022
---
## Question 1
For converting 0.1~10~ to corresponding binary number we follow these steps:
| Number | Integer Part | Fraction part |
| -------- | -------- | -------- |
| 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
As we can observe fraction part is never going to be zero and it is reccursive in nature.From this binary representation is writtenn from top to bottom of integer part.(0011) is repeating reccursively.
(0.1)~10~ = (0.0001100110011...)~2~
---
## Question 2
For converting (0.1)~10~ to binary representation using IEEE 754 standard:
First we decide sign bit. As given number is positive sign bit is zero.
| sign | exponent| mantissa |
| -------- | -------- | -------- |
| 0 |-| - |
Now from above question we know that
(0.1)~10~ = (0.0001100110011...)~2~
As we know before decimal point number should be of range 1 to 9 in scientific notation.
(0.0001100110011001100110011001...)~2~ = (1.100110011001100110011001...)~2~ * 2^-4^
which is finally rounded off to (1.10011001100110011001101)~2~ * 2^-4^
Here by mantissa caluclation is over.
Now we need to calculate the exponent;
so 127-4 = 123.
Now we need to convert 123 to binary representation:
| | Quotient | Remainder |
| -------- | -------- | -------- |
| 123/2 | 61 | 1 |
61/2|30|1
30/2|15|0
15/2|7|1
7/2|3|1
3/2|1|1
1/2|0|1
So we go from down to top in remainder section that is (123)~10~ = (01111011)~2~ which is exponent.
So finally
| sign | exponent | mantissa |
| -------- | -------- | -------- |
| 0 | 01111011 |100 1100 1100 1100 1100 1101
---
## Question 3
First let us convert (0.2)~10~ into binary representation
| Number | Integer Part | Fraction part |
| -------- | -------- | -------- |
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
We can observe reccursion here again.So going from top to bottom in integer part section
(0.001100110011001100110011001)~2~
And we need to make sure number befor decimal point so we move decimal point three bits
that is (1.100110011001100110011001)~2~ * 2^-3^
And we rounded off this to (1.10011001100110011001101)~2~ * 2^-3^
Here by mantissa calculatio is over. Now lets calculate exponent part.
127-3 = 124
So converting 124 to binary representation
| | Quotient | Remainder |
| -------- | -------- | -------- |
| 124/2 | 62 | 0 |
62/2|31|0
31/2|15|1
15/2|7|1
7/2|3|1
3/2|1|1
1/2|0|1
that is (01111100)~2~
And as given number is positive sign bit is 0
| sign | exponent| mantissa |
| -------- | -------- | -------- |
| 0 |01111100|100 1100 1100 1100 1100 1101
So (0.0111110010011001100110011001101)~2~ is binary representation.
Now again converting this binary representation to decimal number:
We take exponent that is:
(01111100)~2~ and convert it to decimal number.
so 0* 2^0^ + 0* 2^1^ + 1* 2^2^ + 1* 2^3^ +1* 2^4^ + 1* 2^5^ +1* 2^6^ + 0*2^7^ = 4+8+16+32+64 = 124
exponent is 124-127 = -3
Now take mantissa part 100 1100 1100 1100 1100 1101 and convert to decimal that is:
1* 2^-1^ +1* 2^-4^+1* 2^-5^+1* 2^-8^+1* 2^-9^+1* 2^-12^+1* 2^-13^+1* 2^-16^+1* 2^-17^+ 1* 2^-20^+1* 2^-21^+1* 2^-23^ = 0.6
Now (-1)^s^(1.mantissa)(exponent) is final decimal representaion.
as s=0;
decimal = 1*(1.6)(2^-3^) == 0.2
---
## Question 4
To represent floating-point numbers and perform addition, we'll adopt a simple approach where each floating-point number is divided into two parts: the integer part and the fractional part. Each part will be stored in separate registers.
**Representation**:
For this example, we'll utilize two registers to store each floating-point number: one for the integer part and another for the fractional part.
For 5.391:
- Register 1: Integer part = 5
- Register 2: Fractional part = 391
For 3.012:
- Register 3: Integer part = 3
- Register 4: Fractional part = 012
**Performing Addition**:
We'll add the fractional parts together. If the sum exceeds 999 (the maximum value of the fractional part), we'll carry over to the integer part. Then, we'll add the integer parts together along with any carryover from the fractional part.
Let's perform the addition:
- Fractional part: 391 + 012 = 403
- Since 403 is within the range of the fractional part (0 to 999), no carryover is needed.
- Integer part: 5 + 3 (no carryover) = 8
So, the result is:
- Register 5: Integer part = 8
- Register 6: Fractional part = 403
Therefore, the result of adding 5.391 and 3.012 is 8.403.
---
## Question 5
```assembly=
.section .data
# Define the two floating-point numbers in IEEE 754 format
number1: .float 7.25 # Example: 7.25
number2: .float -2.75 # Example: -2.75
# Define the memory location to store the result
result: .float 0.0 # Initialize to 0.0
.section .text
.globl _start
_start:
# Load the address of number1 into a register
la t0, number1
# Load the address of number2 into another register
la t1, number2
# Load the first floating-point number into a floating-point register (f0)
flw f0, 0(t0)
# Load the second floating-point number into another floating-point register (f1)
flw f1, 0(t1)
# Perform floating-point addition
fadd.s f2, f0, f1
# Store the result in the memory location
la t2, result
fsw f2, 0(t2)
# Exit the program
li a0, 0 # Exit status
li a7, 93 # Exit system call number
ecall # Invoke system call
```