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.
Start with the provided code file a02.c
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.
***** a02.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;
}
// 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]);
authenticateC(x);
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. ");
}
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started