In RISC-V assembly Now can you calculate the inverse of matrix T that is (A^t x…
- User
In RISC-V assembly Now can you calculate the inverse of matrix T that is (A^t x MatrixCinverse x A)^-1 and store the result in D .data A: .word 1, 1, -2, 1, 3, 1 #, 2, 4 # Matrix A [n x 2] B: .word 0, 0, 0, 0, 0, 0 #, 0, 0 # Transpose of Matrix A (A^T) [2 x n] MatrixC:.word 1,0,0,0,1,0,0,0,1 #The new matrix C, a modification for the Viva MatrixCinverse:.word 0,0,0,0,0,0,0,0,0 #the inverse of matrix C C: .word 0, 0, 0, 0,0,0 # Result of A^T x C^-1 | [2 x 3] T: .word 0,0,0,0 # Result of (A^T x C^-1 x A)| [2 x 2] D: .word 0, 0, 0, 0 # Result of (A^T x C^-1 x A)^-1 | Inverse of Matrix T | [2 x 2] E: .word 0, 0, 0, 0, 0, 0 # [(A^T x C^-1 x A)^-1] x (A^T) | [2 x 2] x [2 x n] --> [2 x n] | Matrix D x Matrix B U: .word 0,0,0,0,0,0 # [(A^T x C^-1 x A)^-1] x (A^T) x C^-1 b: .word 6, 0, 0 # b Matrix | [n x 1] F: .word 0, 0 # [(A^T x A)^-1] x (A^T) x C^-1 x b | [2 x n] x [n x 1] --> [2 x 1] | Matrix U x Matrix b | m | <-- The resultant matrix
| c |
G: .word 4, 2, 2, 2, 2, 2 # Row information of every matrix
.text
Some Initialization
#x-----------------------------x--------------------------------x la s0, A # Base Address of Matrix A la s1, B # Base Address of Matrix B la s3, MatrixC # Base Address of Matrix C( viva part) la s4,MatrixCinverse # Base Address of Matrix C inverse ( viva part) la s2, C # Base Address of C addi a1, zero, 2 addi t1, zero, 0
Calculating Number of Rows in Matrix A and storing it in t2
#x-----------------------------x--------------------------------x Row_Col_Calc: add a0, zero, s0 # COPY(Base Address Mat1) for_count_n: bge a0, s1, for_count_ne addi a0, a0, 4 addi t1, t1, 1 # Counting the Number of Elements in MatA j for_count_n for_count_ne: div a2, t1, a1 # Total_Rows/Cols = total_element / 2 = t1 / 2 | Total_Rows = total_elements / Total_Columns | Total_Cols = total_elements / Total_Rows beq ra, zero, skipC jr ra skipC: #x-----------------------------x--------------------------------x add t2, zero, a2
Finding the tranpose of Matrix A and storing it in Matrix B
#x-----------------------------x--------------------------------x addi t3, zero, 2 # CONSTANT(t3=2) add s10, zero, s0 # COPY(Base Address of Matrix A) add s11, zero, s1 # COPY(Base Address of Matrix B) transpose: addi t5,zero,0 # Outter Loop Counter [CounterOutter = t5] for_outer: bge t5, t3, done_outer # if CounterOutter == 2 addi t6,zero,0 # Reset Inner Counter [InnerCounter = t6] for_inner: bge t6, t2, done_inner # if InnerCounter == Total_Rows lw s3, 0(s10) # Load an element from MatA sw s3, 0(s11) # Store the element from MatA into MatB addi s10, s10, 8 # Increment through MatA by a factor of two addi s11, s11, 4 # Increment through MatB by a factor of one addi t6, t6, 1 # Increment the InnerCounter by 1 j for_inner done_inner: add s10, zero, s0 # COPY(Base Address of Matrix A) addi s10, s10, 4 # Base Address Matrix A + Offset(4) to pick next st of alternate values addi t5, t5, 1 # Increment OutterCounter addi t6,zero,0 # Reset InnerCounter j for_outer done_outer: #x-----------------------------x--------------------------------x
- Assistant