1 / 7

Determinant Calculation of a NxN Matrix Using AT&T Assembly Syntax

Determinant Calculation of a NxN Matrix Using AT&T Assembly Syntax. Algorithm High-level language implementation AT&T assembly language implementation Image of the stack before and after a function is called. Want to compute. Algorithm. Suppose we have a 3x3 matrix:.

uta-winters
Download Presentation

Determinant Calculation of a NxN Matrix Using AT&T Assembly Syntax

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Determinant Calculation of a NxN Matrix Using AT&T Assembly Syntax Algorithm High-level language implementation AT&T assembly language implementation Image of the stack before and after a function is called

  2. Want to compute Algorithm • Suppose we have a 3x3 matrix: • Use the recursive “expansion by minors” method: • Or in general, for a matrix M of NxN dimensions where Msub(N-1)x(N-1) is a sub-matrix of the matrix M whose dimension is (N-1)x(N-1) and does not contain the first row and i column

  3. Algorithm (cont.) • Observations: • If N=2, compute determinant directly (base case) • If N>2, recursive calls must be done successively until N=2 • For each matrix element M(1,i), need to determine the sub-matrix that does not contain the first row and ith column of the “currently computing” matrix.

  4. High-level Language Implementation: C++ int det(int *M, int N) { if (N==2) { return (M[0]*M[3] - M[1]*M[2]); } else { int new_dimension = (N-1); int tdet=0; int *temp = new int[(N-1)*(N-1)]; for (int ref_ele=0; ref_ele<N;ref_ele++) { int counter=0; for (int i=0;i<N;i++) { for (int j=0;j<N;j++) { if ( (j!= ref_ele) && (i!=0)) { temp[counter] = M[(N*i + j)]; counter++; } } } int t = det(temp, new_dimension); if ((ref_ele % 2) != 0) t = (-1)*t; tdet += M[ref_ele]*t; } return tdet; } }

  5. AT&T Assembly Language Implementation • Specification of the determinant function “det” in the assembly language implementation. The following steps must be done successively: • All elements of the matrix M must be “PUSHED” onto the stack, in the major-row ordered, before the “det” function is called • The dimension N of the matrix M must also be “PUSHED” onto the stack • A variable that will hold the result of the determinant of the currently computing matrix must also be PUSHED onto the stack (make space for the return result) • A variable that will hold an error flag, if ever occurs, must also be “PUSHED” onto the stack (make space for the return error) • See attachment sheets for the program.

  6. Error Flag: (0=no error, 1= error) Result: will contain the determinant N: dimension of Matrix M M[0] M[1] M[3] M[4] …… …… M[N2 – 1] The Image of the Stack “Just” Before the “det” Function Is Called Stack pointer: %esp

  7. Address of the next instruction in the caller to be executed after returning from the function call Error Flag: (0=no error, 1= error) Result: will contain the determinant N: dimension of Matrix M M[0] M[1] M[3] M[4] …… …… M[N2 – 1] The Image of the Stack “Just” AFTER the “det” Function Is Called Stack pointer: %esp

More Related