# Computer Organization Lab 7
Name: T.Venkat Kaushal
Roll Number: CS22B058
---
## Question 1
Given number = (0.1)~10~
1. Converting this number in to decimal:
### Step 1: Convert the intergral part of the number into binary.
The integral part in (0.1)~10~ is 0.
The decimal part of 0 is 0.
### Step2: Convert the fractional part of the number into binary.
The fractional part in (0.1)~10~ is 0.1 .
To get the binary format of this fractional part, we follow the standard procedure of multiplication by 2 and taking out the integral part collect all integral part and follow this until we get 1.0 .
0.1 * 2 = 0.2
0.2 * 2 = 0.4
0.4 * 2 = 0.8
0.8 * 2 = 1.6 -> 0.6
0.6 * 2 = 1.2 -> 0.2
and the same repeats...
The binary representation is: (0.000110011....)~2~ = 1.1(0011)^*^~2~ * 2^123^.
---
## Question 2
Convert (0.1)~10~ in binary using IEEE 754 standard.
In the Last Question we saw (0.1)~10~ can be represented as: 1.1(0011)^*^~2~ * 2^123^.
To this to store in IEEE 754 Standard:
We know that IEEE 754 standard has
1. 1 bit: sign bit
2. 8 bits : exponent(1-255)
3. 23 bits : mantissa
So, for (0.1)~10~.
1. sign bit : 0
2. exponent : 01111011
3. mantissa : 10011001100110011001100
The IEEE 32 bit encoding looks like: 0|01111011|10011001100110011001100.
---
## Question 3
Given number = (0.2)~10~
1. Converting this number in to decimal:
### Step 1: Convert the intergral part of the number into binary.
The integral part in (0.2)~10~ is 0.
The decimal part of 0 is 0.
### Step2: Convert the fractional part of the number into binary.
The fractional part in (0.2)~10~ is 0.2 .
To get the binary format of this fractional part, we follow the standard procedure of multiplication by 2 and taking out the integral part collect all integral part and follow this until we get 1.0 .
0.2 * 2 = 0.4
0.4 * 2 = 0.8
0.8 * 2 = 1.6 -> 0.6
0.6 * 2 = 1.2 -> 0.2
and the same repeats...
The binary representation is: (0.0011...)~2~ = 1.1(0011)^*^~2~ * 2^124^.
Convert (0.2)~10~ in binary using IEEE 754 standard.
In the Last Question we saw (0.2)~10~ can be represented as: 1.1(0011)^*^~2~ * 2^124^.
To this to store in IEEE 754 Standard:
We know that IEEE 754 standard has
1. 1 bit: sign bit
2. 8 bits : exponent(1-255)
3. 23 bits : mantissa
So, for (0.1)~10~.
1. sign bit : 0
2. exponent : 01111100
3. mantissa : 10011001100110011001100
The IEEE 32 bit encoding looks like: 0|01111100|10011001100110011001100.
Converting back(Binary to decimal):
1. (0.0011...)~2~ = 0.19999998807907104492(approximately equals to 2).
---
## Question 4
Design a representation for floating point numbers:
1. Given we have a floating point number, with
* m number of bits for integral part of the floating point number, store in a 32 bit register.
* n number of bits for fractional part of the floating point number, store it in another 32 bit register.
* We take a factor = 10^n^
* Now we add the integral parts and fractional parts seperately.
* If the fractional part sum > the factor, then the fractional part creates a carry, the carry can be calculated as:
* carry = fractional sum / factor.
* Add this carry to the integral sum
* So {integral Sum + carry}.{fractional sum % factor} is the required resultant addition.
2. Example:
* a = 2.123, b = 3.413
* The factor is 1000
* integral sum = 2 + 3 = 5
* fractional sum = 123 + 413 = 536 < 1000
* carry = 536/1000 = 0
* floating point number = {5 + 0}.{536} = 5.536
---
## Question 5
```assembly=
.text
main:
li x1, 0x40026C43
li x2, 0x4002D70A
# Extract the sign, exponent, and mantissa of the first number
lui x31 0x80000
addi x31 x31 0x000
and x3, x1, x31 # Extract sign bit (bit 31)
lui x30 0x7F800
addi x30 x30 0x000
and x4, x1, x30 # Extract exponent bits (bits 30-23)
lui x29 0x007FFF
addi x29 x29 0xFF
and x5, x1, x29 # Extract mantissa bits (bits 22-0)
# Extract the sign, exponent, and mantissa of the second number
and x6, x2, x31 # Extract sign bit (bit 31)
and x7, x2, x30 # Extract exponent bits (bits 30-23)
and x8, x2, x29 # Extract mantissa bits (bits 22-0)
# Perform the addition of the mantissas
add x9, x5, x8 # Add the mantissas
# Combine the sign, exponent, and mantissa to form the result
or x10, x3, x4 # Combine sign and exponent of the first number
or x11, x6, x7 # Combine sign and exponent of the second number
or x12, x9, x10 # Combine mantissa and combined sign/exponent of the first number
or x13, x11, x12 # Combine mantissa and combined sign/exponent of the second number
# Store the result back to memory or another register if needed
sw x13, result_address(x0) # Store the result in memory at result_address
nop
.data
result_address: .word 0x00000104
```