Question: In this exercise your goal is to implement a function that checks whether a supplied NxN matrix is an identity matrix. Recall that an identity

"In this exercise your goal is to implement a function that checks whether a supplied NxN matrix is an identity matrix. Recall that an identity matrix has 1 in each entry on the leading diagonal, and 0 in all other entries. The function is passed two parameters:

a pointer to the first element in the matrix (effectively &m[0][0] in the argument register $a0

the number of rows and columns in the matrix (the parameter n in the C code) in register $a1

The function should behave in the same way as the is_ident() function in the isi.c file." The function in the isi.c file is as follows:

int is_ident(int m[N][N], int n)

{

for (int row = 0; row < n; row++) {

for (int col = 0; col < n; col++) {

if (row == col) {

if (m[row][col] != 1) return 0;

} else {

if (m[row][col] != 0) return 0;

}

}

}

return 1;

} The isi.s eqivalent given is (the prologue and epilogue don't need to be changed unless extra registers are to be added: NOTE: This is in MIPS

.text .globl is_ident

# params: m=$a0, n=$a1 is_ident: # prologue addi $sp, $sp, -4 sw $fp, ($sp) la $fp, ($sp) addi $sp, $sp, -4 sw $ra, ($sp) addi $sp, $sp, -4 sw $s0, ($sp) addi $sp, $sp, -4 sw $s1, ($sp) addi $sp, $sp, -4 sw $s2, ($sp) addi $sp, $sp, -4 sw $s3, ($sp) # if you need to save more than four $s? registers # add extra code here to save them on the stack

# ... your code for the body of is_ident(m,N) goes here ...

# epilogue # if you saved more than four $s? registers # add extra code here to restore them lw $s3, ($sp) addi $sp, $sp, 4 lw $s2, ($sp) addi $sp, $sp, 4 lw $s1, ($sp) addi $sp, $sp, 4 lw $s0, ($sp) addi $sp, $sp, 4 lw $ra, ($sp) addi $sp, $sp, 4 lw $fp, ($sp) addi $sp, $sp, 4 j $ra I'll also link the bitbucket repository with all the source code in case you need to refer to that (its too much to put onto here) https://bitbucket.org/Raze_One/chegg/src/5767d2c3c94f0fa3cc2929d30f8dc97919a69954/ Thanks in advance

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!