Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

In the following code, we have omitted the definitions of constants M and N: #de

ID: 3834876 • Letter: I

Question

In the following code, we have omitted the definitions of constants M and N: #define M/* Mystery number 1 */#define N/* Mystery number 2 */unsigned int arith (unsigned int x, unsigned int y){unsigned int result = 0; result = x * M + y/N; return result;} We compiled this code for particular values of M and N. The compiler optimized the multiplication and division. The following is a translation of the generated machine code back into C: unsigned int optarith (unsigned int x, unsigned int y) {unsigned int t = 3 * x; x = 4; y = y/3; return x + y;} What are the values of M and N? (show work)

Explanation / Answer

The value of M is 58 and the value of N is 48

Explanation
It is given from the method 'arith' that the result = (x*M + y/N) -> Let this be equation 1.
We now try to convert the reverse engineered C code to the same format.

a.
In optarith method, we can see that y is being divided by 24 and then again by 3
y >>= 4                  (is equivalent to y/24 = y/16)
y = y/3;

so overall we are divinding y by 16*3 = 48. We now compare this with y/N in equation 1. We can clearly see that the value of N is 48.

b. In optarith method,
t = 3*x
x << = 6    (is equal to x = x*26)
x -= 2*t      (is equal to x = x-2t)

For convention, let's name variables differently at each assignment step
t = 3*x
x1 = x*26
x2 = (x1 - 2*t) = (x*26 - 2*3*x) = (64x - 6x) = x*58

Now compare this with (x*M) term in equation 1 and we find the value of M to be 58.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote