Question: Write a function void add _ with _ overflow ( uint 3 2 _ t x , uint 3 2 _ t y , uint

Write a function
void add_with_overflow(uint32_t x, uint32_t y, uint32_t* result_upper, uint32_t* result_lower);
This function should perform the addition x + y. However, note that x + y may overflow, so it might not be representable in 32 bits. You should use the two 32 bit result pointers to store the results of the addition so that if I treat result_upper and result_lower together as a single 64-bit number, the output of your addition will be correct. Do not use any 64-bit numbers in your function including implicitly casting any 32-bit integers to 64-bits. Here are some examples:
uint32_t ru, rl;
add_with_overflow(0x00000001,0x00000002, &ru, &rl);
// ru =0x00000000, rl =0x00000003
add_with_overflow(0xFFFFFFFF,0x00000001, &ru, &rl);
// ru =0x00000001, rl =0x00000000
add_with_overflow(0xC82105D2,0x720AF4E0, &ru, &rl);
// ru =0x00000001, rl =0x3A2BFAB2

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!