5 (18 points) Analyze the following program (without actually running it!), and
ID: 3875577 • Letter: 5
Question
5 (18 points) Analyze the following program (without actually running it!), and determine the decimal values of the 8-bit integer (char) variables a, b, c, u, v, w, x, y, and z when the program finally hangs up in the while(1) loop Once you have done this, you should cut and paste this program into an MPLAB project, and then single step through the program using MPSIM to verify your answers... but PLEASE don't do this before you analyze the program! (On a test you may be asked to analyze a similar program without being allowed to step through it using MPSIM!) Use the "Step Into" button in order to step into the functions and follow their execution. n16 Problem 5 char scramble (char) function prototype statenent tells the compiler that a function // named "scranble will appear later that accepts one // character argument and returns a character value void unscramble (char, char *); const unsigned char Codes (7,2,9,6,4,3,5 Note "const" used to force this array const unsigned char Codevalues[ ] {9,8,5, 1,2,6,3); (table) into flash program nemory void main (void) char a, b. c. u. v. w. x, y. zi for(y = 0; yExplanation / Answer
The answer of the question is:
a=3,b=3,c=7
u=5,v= 9,w=0,
x=85,y=10,z=12
Program I run on online c compiler is as below:
#include<stdio.h>
char scramble (char);
void unscramble (char, char *);
const unsigned char Codes[] = {7,2,9,6,4,3,5};
const unsigned char CodeValues[] = {9,8,5,1,2,6,3};
int main()
{
char a,b,c,u,v,w,x,y,z;
x=0;c=1;b=2;
for (y=0;y<=5; y++)
{
c++;
x = x+y*c;
}
z = x/c;
a = 27%4;
for (y=0;y<=9; y++);
b++;
u = scramble (9);
unscramble (u, &v);
w = scramble(8);
//while (1);
printf ("%d,%d %d %d %d,%d %d %d %d",a,b,c,u, v,w,x,y,z);
return 0;
}
char scramble (char a)
{
char i, val=0;
for (i=0; i<sizeof (Codes); i++)
{
if (a == Codes[i])
{
val = CodeValues[i];
break;
}
}
return val;
}
void unscramble (char a, char *val)
{
char i;
for (i=0; i<sizeof (CodeValues); i++)
{
if (a == CodeValues[i])
{
*val = Codes[i];
break;
}
}
}
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.