Computer Systems A Programmers Perspective 3rd Edition 365 h

Computer Systems: A Programmer\'s Perspective, 3rd Edition, 3.65:
https://www.chegg.com/homework-help/Computer-Systems-3rd-edition-chapter-3-problem-65HWP-solution-9780134092669
In addition, add this as part D of problem 3.65: Write a C code version of transpose() that makes use of the optimizations that are found in the compiler-generated loop. Use the parameter M in your code rather than numeric constants.

Solution


A. M = 13. (52/4)
B. %edi -> i , %ecx -> j
The sample version of code using a resiger (%ebx) to save the adress of A[j][i]
and then add an offset to update A[j+1][i]. MeanWhile it use another resiger (%esi)
to save the base adress of A[i][x]
c.
void transpose(int M, int A[M][M])
{
   int i, j;
   int t = 0;
   int *p_row;
   int *p_col;

   for (i = 0; i < M; i++)
   {
       p_row = &A[i][0]; // use a variable to save base address
       p_col = &A[0][j]; // the same above
       for (j = 0; j < M, j++)
       {
           t = *p_row;
           *p_row = *p_col;
           *p_col = t;
           p_row++; // A[i+1] same as line 5 in assmbly
           p_col += M; // add offset
       }
   }
}

Computer Systems: A Programmer\'s Perspective, 3rd Edition, 3.65: https://www.chegg.com/homework-help/Computer-Systems-3rd-edition-chapter-3-problem-65HWP-solut

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site