Question: for this assignment you will be asked to write a function or two. You will be writing these functions partly in assembly language, using gcc's

for this assignment you will be asked to write a function or two. You will be writing these functions partly in assembly language, using gcc's inline assembler. You are only allowed to set local variables for input and output into your assembly code and return any requested output value. All other tasks (arithmetic, checking for conditions) need to be done in assembly code.

You working on a top secret project. You are asked to write a function in assembly code that will authenticate the user as being able to access a secret number (because the spies know C but don't know any assembly :) ). The input will be an unsigned integer ( x > 0) passed in as the first argument.

To do the authentication:

1. calculate the value 4*x + 7 where x is the input value from the user. 2. XOR this with the number 0xDEAD (57005 in decimal). 3. if this value is larger than or equal to 0xDEAD, then the user is authenticated to get the secret value. Set the return value to 1. 4. if this value is less than to 0xDEAD, then the user is not authenticated. Set the return value to 0.

NOTE: When printing the unsigned values using printf, use the '%u' placeholder.

Once the user is authenticated, you now need to calculate the secret number, again, in assembly code. Take the user's inputed number and typecast it to a float. Then use it to calculate the following floating point number:

fnum = 2.25*sqrt(3.45 + fx*fx)

fnum is a double precision floating point number and fx is the double equivalent of the passed in number. You can use either the x87 FPU or the SSE floating-point assembly. Like the regular part, you can create local variables for input into the assembly code (you may have to for 'constants' since there is no way to set them in assembly code.) and for output and returning the result.

Start with the provided code file a02p.c

HOW TO COMPILE THE CODE FOR ASSIGNMENT 2

Because the code for both versions of this assignment calls the sqrt() function from math.h, you will need to compile it as follows:

gcc -Wall a02p.c -lm -o a02p

REQUIRED PLATFORM

I grade your code on a Linux system running gcc version 5.4.0 Your code should be portable enough to compile and run correctly on any Linux machine.

GRADING YOUR CODE

Your code needs to compile without errors or warnings and run correctly (use the -Wall flag while developing your code). Code that does not compile will receive 0 points. Code that crashes will receive 0 points.

Please don't use filenames with spaces or '-' in it. These names don't work with my grading scripts.

***** a02p.c *****

#include

#include

#include

// do not change anything above this comment

unsigned int authenticate(unsigned int x)

{

unsigned int okay = 0;

/* Here is where you will put the assembly code to authenticate

* the user:

* 1. calculate the value 4*x + 7 where x is the input value.

* 2. XOR this with the number 0xDEAD (57005 in decimal).

* 3. if this value is larger than or equal to 0xDEAD,

* then the user is authenticated. Set the return value to 1.

* 4. if this value is less than to 0xDEAD, then the user is not

* authenticated. Set the return value to 0.

*/

return okay;

}

// this is for debugging purposes so you can compare values

unsigned int authenticateC(unsigned int x)

{

/* this C implementation of the value computation is provided

* so you can compare its correct results with the results of

* your assembly code.

* you can break up the calculation process and put printf

* statements various stages of calculation against your asm code.

*/

unsigned int c = 0xDEAD; /*57005*/

unsigned int y, res;

y = 4*x + 7;

res = c^y;

//printf("%u ",res);

if(res <= c)

return 1;

else

return 0;

}

double calcSecretNumber(double x)

{

double result = 0.0;

/* need to calculate and return

* the secret number using this

* formula:

* fnum = 2.25*sqrt(3.45 + fx^2)

*/

return result;

}

// this is for debugging purposes so you can compare values

double calcSecretNumberC(double fx)

{

/* this C implementation of the value computation is provided

* so you can compare its correct results with the results of

* your assembly code.

* you can break up the calculation process and put printf

* statements various stages of calculation against your asm code.

*/

double fnum = 2.25*sqrt(3.45 + fx*fx);

printf("%10.4f ", fnum);

return fnum;

}

// you can change things for debugging

// purposes (like running the C

// versions of functions). but PLEASE MAKE SURE TO

// TURN IN THE ORIGINAL CODE BELOW

// THIS LINE.

int main (int argc, char **argv)

{

int x, xC;

printf("CS201 - Assignment 02 - I. Forgot ");

if (argc != 2)

{

printf("need 1 argument: an integer number ");

return -1;

}

x = (unsigned int) atoi(argv[1]);

if(!authenticate(x))

{

printf("WARNING! You are not authorized to run this program! ");

printf("This attempt will be logged! ");

}

else

{

printf("You are authorized to see the secret number. ");

double result = calcSecretNumber((double) x);

if(result == -1)

{

printf("Sorry! the secret number couldn't be calculated. Please try again.");

}

else

{

printf("Here is the secret number: %10.4f ", result);

}

}

return 0;

}

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!