# Lab 07 Name: CHATSE SIDDHANT MADHUKAR Roll No.: CS22B016 --- ## Question 1 Multiply the fractional part by 2. Take the integer part of the result as the binary digit. Repeat the process with the fractional part obtained. 0.1 * 2 = 0.2, integer part = 0 (first binary digit) 0.2 * 2 = 0.4, integer part = 0 (second binary digit) 0.4 * 2 = 0.8, integer part = 0 (third binary digit) 0.8 * 2 = 1.6, integer part = 1 (fourth binary digit) 0.6 * 2 = 1.2, integer part = 1 (fifth binary digit) 0.2 * 2 = 0.4, integer part = 0 (sixth binary digit) 0.4 * 2 = 0.8, integer part = 0 (seventh binary digit) 0.8 * 2 = 1.6, integer part = 1 (eigth binary digit) 0.6 * 2 = 1.2, integer part = 1 (ninth binary digit) 0.2 * 2 = 0.4, integer part = 0 (tenth binary digit) this will keep repeating **Answer:** 0.1<sub>10</sub> in binary is **0.0001100110...** --- ## Question 2 - 0.1<sub>10</sub> to binary using IEEE 754 standard : **1.1001100110001011*2<sup>-4</sup>** - 32 bit representation: **0 01111011 10011001100110011001100** - Here 32 bit representation first bit is sign bit, next 8 bits are exponent in which for here it's 127-4 = 123. Next 23 bits are mantissa which will store decimal number portion of power representation. --- ## Question 3 0.2 * 2 = 0.4 0.4 * 2 = 0.8 0.8 * 2 = 1.6 0.6 * 2 = 1.2 0.2 * 2 = 0.4 0.4 * 2 = 0.8 0.8 * 2 = 1.6 0.6 * 2 = 1.2 - 0.2<sub>10</sub> to binary using IEEE 754 standard : **1.1001100110001011*2<sup>-3</sup>** - 32 bit representation: **0 01111100 10011001100110011001100** - 1.1001100110001011*2<sup>-3</sup> decimal value is **0.199993133** --- ## Question 4 we can represent a floating-point number in the following way: - I can outline a basic representation for floating-point numbers and then demonstrate how to perform addition using this representation. Let's assume we're working with single-precision floating-point numbers, which typically use 32 bits. - let's represent each floating-point number using two registers: one for the integer part and one for the fractional part. We'll assume both parts are stored using 16 bits each. - **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. 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 = **0**0000000000000101 0.391 = 0110010000011000 3.012 = 3 + 0.012 3 = **0**0000000000000011 0.012 = 0000001100010010 0.391 + 0.012 = 0110011100111010 carry = 0 5 + 3 + carry = **0**0000000000001000 **Final sum:** **0**0000000000001000.0110011100111010 --- ## Question 5 **Assembly Code:** ```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) ``` - This code assumes that the floating-point numbers are stored as single-precision floating-point values (32 bits each) in IEEE 754 format. The lw instruction loads a word (32 bits) from memory into a register, and the sw instruction stores a word from a register into memory. - Make sure to replace num1, num2, and result with the appropriate memory addresses where the floating-point numbers are stored and where you want to store the result. Additionally, ensure that your RISC-V assembler supports floating-point instructions and registers. ---