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

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:

4. Analyze the x86-64 assembly given below. char out. subq $8 Brsp movsb Sdil Sedi call putchar addq $8 Brsp ret. sub mystery: subq $8 Brsp $9 Srdi. cmpq ja L4 addl. $48 sedi movsb Sdil. Sedi call char ut. L3 addl. $55 Sedi movsbl Sdil. Sedi call char out addq $8 Brsp ret. mystery pushq 12 pushq Srbp pushq Srbx srdi, Srax movq movl $1 Sebx L8 L9 salq $4 Srb shrq $4 Srax $15 Srax cimpq ja L9 movl $0 Bebp L10 L11 mova Srdi Srax movl $0 Sedx diva Srbx nova Srdx Sr12 Srax Srdi movq call sub mystery addl. $1 Bebp movq Sr12 Srdi. shrq $4 Srb L10 test Srbx Srbx L11 ne movl sebp, Seax popq Srbx Srbp popq sr12 popq ret Parameter 1 in Sdil Sedi. putchar is a C function that writes (prints) a single char to stdout (the screen) Parameter 1 in srdi Saving registers, not relevant. Parameter 1 in srdi, copy into Local 1, Srax. Local 2 in Sebx (or Srbx ocal 3 in Bebp/rbp, it's not the base pointer L Division instruction divides srax srbx Remainder is stored in Brdx. Quotient is stored in srax. Restoring saved registers, also not relevant.

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.

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