Hello, I am looking for help with the following questions and I have the followi
ID: 3827143 • Letter: H
Question
Hello, I am looking for help with the following questions and I have the following code already:
// Q4A
//
//
//
void char_out(char P1)
{
putchar(P1);
}
// Q4B
//
//
//
void sub_mystery(uint64_t P1)
{
if (P1 > 9)
{
uint64_t L1;
L1 = P1 + 55;
char_out(L1);
}
else
{
uint64_t L1;
L1 = P1 + 48;
char_out(L1);
}
}
// Q4C
//
//
//
int mystery(uint64_t P1)
{
uint64_t L1 = P1;
uint64_t L2 = 1;
while(L1 > 15)
{
L2 = L2 >> 4;
L1 = L1 << 4;
}
uint64_t L3 = 0;
while(L2 != 0)
{
L1 = P1;
int L4 = 0;
L4 = L1 / L2;
uint64_t L5 = L4;
sub_mystery(L1);
L3++;
P1 = L5;
L2 = L2 << 4;
}
return L3;
}
The question being:
Explanation / Answer
Hi,
please find the anser to the question below:-
there are few modification which is highlighted in bold and rest the modules are expalined with comments .
Please find the edited code below:-
CODE:-
//This function will display the character in P1 on console when the program runs
void char_out(char P1)
{
putchar(P1);
}
// Q4B
//This program will take an integer input P1 which is checked for value>9 if the value is greater than 9 then a new variable
//which will be local is declared and it will have value P1+55 and that value will be displayed on the console by calling it in
//charout fucntion
//If value is <9 thn 48 is added to P1 and that value is put to console by calling out char_out
void sub_mystery(uint64_t P1)
{
if (P1 > 9)
{
uint64_t L1;
L1 = P1 + 55;
char_out(L1);
}
else
{
uint64_t L1;
L1 = P1 + 48;
char_out(L1);
}
}
// Q4C
//This fucntion willtake the input integer variable P1 and will assign to local variable L1 another local variable l1 is declared which
//has value 1
//The comaprison is done whether the L1 value is > 15 if it is then
//L2 goes to shift arithmetic left and L1 goes to shift logical right
//If not then a new local variable L3 is set to 0 and again check is applied if L2 is not equal to zero
//If it is not then the p1 value is assigned to L1 new int variable is declared having value 0
//The division is performed on lines L4=L1/L2 and assign the value of L4 to a new local varaible L5.
//then call function sub_mystery(L1)
//The Value of L3 is incremented by when sub_mystery returns and the local variable value of L5 is assigned to P1 and the L3 goes to logical right shift again.
//finally when the mystery() returns it will return the L3 value.
int mystery(uint64_t P1)
{
uint64_t L1 = P1;
uint64_t L2 = 1;
if (L1 > 15)
{
L2 = L2 >> 4;
L1 = L1 << 4;
}
uint64_t L3 = 0;
if (L2 != 0)
{
L1 = P1;
int L4 = 0;
L4 = L1 / L2;
uint64_t L5 = L4;
sub_mystery(L1);
L3++;
P1 = L5;
L2 = L2 << 4;
}
return L3;
}
=====================================================================================
Please let me know in case of clarification.
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.