Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

This problem requires you to add two positive only IEEE floating point numbers together by emulating the floating point hardware in software. In C language

This problem requires you to add two positive only IEEE floating point numbers together by emulating the floating point hardware in software. In C language please. There is start up code that was provided and has to be built off of!

image text in transcribed

/*****************************************************************/

/* Assign 2 template */

/*****************************************************************/

#include

typedef union float_32{

float floating_value_in_32_bits;

int arg_32;

struct sign_exp_mantissa{

unsigned mantissa:23;

unsigned exponent:8;

unsigned sign:1;

} f_bits;

struct single_bits{

unsigned b0 :1;

unsigned b1 :1;

unsigned b2 :1;

unsigned b3 :1;

unsigned b4 :1;

unsigned b5 :1;

unsigned b6 :1;

unsigned b7 :1;

unsigned b8 :1;

unsigned b9 :1;

unsigned b10:1;

unsigned b11:1;

unsigned b12:1;

unsigned b13:1;

unsigned b14:1;

unsigned b15:1;

unsigned b16:1;

unsigned b17:1;

unsigned b18:1;

unsigned b19:1;

unsigned b20:1;

unsigned b21:1;

unsigned b22:1;

unsigned b23:1;

unsigned b24:1;

unsigned b25:1;

unsigned b26:1;

unsigned b27:1;

unsigned b28:1;

unsigned b29:1;

unsigned b30:1;

unsigned b31:1;

}bit;

} FLOAT_UN;

// A function to print out bits from a 32 bit container

// provided by the union FLOAT_UN above, and using

// a text string as a label for the bit string

// as passed in the second argument

int print_bits(FLOAT_UN float_32, char * text){

char bit_string[43];

int i,j;

for(i=0; i

bit_string[i] = ' ';

}

bit_string[42] = '\0';

bit_string[0] = float_32.bit.b31?'1':'0';

bit_string[2] = float_32.bit.b30?'1':'0';

bit_string[3] = float_32.bit.b29?'1':'0';

bit_string[4] = float_32.bit.b28?'1':'0';

bit_string[5] = float_32.bit.b27?'1':'0';

bit_string[7] = float_32.bit.b26?'1':'0';

bit_string[8] = float_32.bit.b25?'1':'0';

bit_string[9] = float_32.bit.b24?'1':'0';

bit_string[10] = float_32.bit.b23?'1':'0';

bit_string[12] = float_32.bit.b22?'1':'0';

bit_string[13] = float_32.bit.b21?'1':'0';

bit_string[14] = float_32.bit.b20?'1':'0';

bit_string[16] = float_32.bit.b19?'1':'0';

bit_string[17] = float_32.bit.b18?'1':'0';

bit_string[18] = float_32.bit.b17?'1':'0';

bit_string[19] = float_32.bit.b16?'1':'0';

bit_string[21] = float_32.bit.b15?'1':'0';

bit_string[22] = float_32.bit.b14?'1':'0';

bit_string[23] = float_32.bit.b13?'1':'0';

bit_string[24] = float_32.bit.b12?'1':'0';

bit_string[26] = float_32.bit.b11?'1':'0';

bit_string[27] = float_32.bit.b10?'1':'0';

bit_string[28] = float_32.bit.b9?'1':'0';

bit_string[29] = float_32.bit.b8?'1':'0';

bit_string[31] = float_32.bit.b7?'1':'0';

bit_string[32] = float_32.bit.b6?'1':'0';

bit_string[33] = float_32.bit.b5?'1':'0';

bit_string[34] = float_32.bit.b4?'1':'0';

bit_string[36] = float_32.bit.b3?'1':'0';

bit_string[37] = float_32.bit.b2?'1':'0';

bit_string[38] = float_32.bit.b1?'1':'0';

bit_string[39] = float_32.bit.b0?'1':'0';

printf("%23s %s ",text, bit_string);

return 0;

}

int main(int argc, char * argv[])

{

FLOAT_UN float_32_s1, float_32_s2, float_32_rslt, fun_arg;

/**local helper variables**/

float the_hardware_result;

int mant_s1, mant_s2, mant_res, exp_s1, exp_s2;

int i, j, k, shift_count;

/* Request two FP numbers */

printf("please enter your first floating point number and new-line: ");

scanf("%g", &float_32_s1.floating_value_in_32_bits);

printf("please enter your second floating point number and new-line: ");

scanf("%g", &float_32_s2.floating_value_in_32_bits);

/* generate floating point hardware result */

/* Get the mantissa and exponent components */

/* into the helper variables */

mant_s1 = float_32_s1.f_bits.mantissa;

mant_s2 = float_32_s2.f_bits.mantissa;

exp_s1 = float_32_s1.f_bits.exponent;

exp_s2 = float_32_s2.f_bits.exponent;

/** check for normalization and slam in the **/

/** hidden bit if normalized **/

/** The rest is left to you */

}

This problem requires you to add two positive only IEEE floating point numbers together by emulating the floating point hardware in software 1. You are only allowed to use the integer operations in C (i.e. shift, integer add, bitwise logical operators, etc.) to do the addition. 2. You will need to scan in two floating point numbers into unions which allows access to the mantissa, exponent and sign components as shown in class. 3. Using the bit field components of the two numbers you must compute the result of their addition and rebuild a new floating point number which you can printf as output. As shown below, you must include printed bit output which shows the steps you're using to complete the addition. Your program interface must look like what follows between the two lines of asterisks. (What is below that second line of them are descriptive hints for you.) This program will emulate the addition of two IEEE 754 floating point numbers Please enter two positive floating point values each with: -no more than 6 significant digits - a value between 10**37 and 10**-37 Enter Float 1: 34.5 Enter Float 2: 1.250 Original pattern of Float 1: 0 1000 0100 000 1010 0000 0000 0000 0000 Original pattern of Float 2: 0 0111 1111 010 0000 0000 0000 0000 0000 Bit pattern of result0 1000 0100 000 1111 0000 0000 0000 0000 EMULATED FLOATING RESULT FROM PRINTF>>35.75 HARDWARE FLOATING RESULT FROM PRINTF>>35.75 To get the result of the addition constructed into the union for the example shown above you must: -COPY THE MASNTISSA PARTS INTO THEIR OWN HELPER INT VARIABLES AND -EXPOSE HIDDEN BITS INTO MANTISSA HELPER VARIABLES TO GET 24 BITS: Slam hidden bit into Float 1: 1000 1010 0000 0000 0000 0000 Slam hidden bit into Float 2: 1010 0000 0000 0000 0000 0000 -SHIFT MANTISSA OF SMALER VALUE FOR COMMON EXPONENT: Post shift pattern of mant. 1: 1000 1010 0000 0000 0000 0000 Post shift pattern of mant. 2: 0000 0101 0000 0000 0000 0000 -ADD AND ADJUST FINAL MANTISSA OF RESULT: Bit sums before adjustment:1000 1111 0000 0000 0000 0000 -SINCE HIDDEN BIT IS PERFECT FOR RESULT JUST REMOVE IT Final 23 bit pattern for result: 000 1111 0000 0000 0000 0000 -NOW PUT RESULT INTO THE MANTISSA BIT PART OF THE FINAL ANSWER -WITH COMMON EXPONENT AND CORRECT SIGN PLACED IN THEIR BIT FIELDS AND PRINT THE UNIT AS A FLOAT .You must generate output for at least the numbers that are found in this file on Blackboard: COMP3050_Assignment2_testdata.txt This problem requires you to add two positive only IEEE floating point numbers together by emulating the floating point hardware in software 1. You are only allowed to use the integer operations in C (i.e. shift, integer add, bitwise logical operators, etc.) to do the addition. 2. You will need to scan in two floating point numbers into unions which allows access to the mantissa, exponent and sign components as shown in class. 3. Using the bit field components of the two numbers you must compute the result of their addition and rebuild a new floating point number which you can printf as output. As shown below, you must include printed bit output which shows the steps you're using to complete the addition. Your program interface must look like what follows between the two lines of asterisks. (What is below that second line of them are descriptive hints for you.) This program will emulate the addition of two IEEE 754 floating point numbers Please enter two positive floating point values each with: -no more than 6 significant digits - a value between 10**37 and 10**-37 Enter Float 1: 34.5 Enter Float 2: 1.250 Original pattern of Float 1: 0 1000 0100 000 1010 0000 0000 0000 0000 Original pattern of Float 2: 0 0111 1111 010 0000 0000 0000 0000 0000 Bit pattern of result0 1000 0100 000 1111 0000 0000 0000 0000 EMULATED FLOATING RESULT FROM PRINTF>>35.75 HARDWARE FLOATING RESULT FROM PRINTF>>35.75 To get the result of the addition constructed into the union for the example shown above you must: -COPY THE MASNTISSA PARTS INTO THEIR OWN HELPER INT VARIABLES AND -EXPOSE HIDDEN BITS INTO MANTISSA HELPER VARIABLES TO GET 24 BITS: Slam hidden bit into Float 1: 1000 1010 0000 0000 0000 0000 Slam hidden bit into Float 2: 1010 0000 0000 0000 0000 0000 -SHIFT MANTISSA OF SMALER VALUE FOR COMMON EXPONENT: Post shift pattern of mant. 1: 1000 1010 0000 0000 0000 0000 Post shift pattern of mant. 2: 0000 0101 0000 0000 0000 0000 -ADD AND ADJUST FINAL MANTISSA OF RESULT: Bit sums before adjustment:1000 1111 0000 0000 0000 0000 -SINCE HIDDEN BIT IS PERFECT FOR RESULT JUST REMOVE IT Final 23 bit pattern for result: 000 1111 0000 0000 0000 0000 -NOW PUT RESULT INTO THE MANTISSA BIT PART OF THE FINAL ANSWER -WITH COMMON EXPONENT AND CORRECT SIGN PLACED IN THEIR BIT FIELDS AND PRINT THE UNIT AS A FLOAT .You must generate output for at least the numbers that are found in this file on Blackboard: COMP3050_Assignment2_testdata.txt

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases On The Web Designing And Programming For Network Access

Authors: Patricia Ju

1st Edition

1558515100, 978-1558515109

More Books

Students also viewed these Databases questions