Question

In: Computer Science

Write a MIPS assembly language to transpose a square integer matrix in code

Write a MIPS assembly language to transpose a square integer matrix

in code

Solutions

Expert Solution

1). ANSWER :

GIVENTHAT :

To Write a MIPS assembly language to transpose a square integer matrix

Program:

Sample output:

Code to copy:

################# transpose.asm ###################
.data
array:   .word 1 2 3
   .word 4 5 6
   .word 7 8 9
arrend:
rowSize: .word 3
colSize: .word 3
orgMatr: .asciiz "Original matrix:\n"
traMatr: .asciiz "Transpose of the given matrix:\n"
newLine: .asciiz "\n"
space: .asciiz " "
.text
main:
   # print original matrix
   la $a0,orgMatr
   li $v0,4
   syscall
   jal PrintMatrix
   # find transpose of the given matrix
   jal TransposeMatrix
   # print the transposed matrix
   la $a0,traMatr
   li $v0,4
   syscall
   jal PrintMatrix
li $v0,10
syscall
################# PrintMatrix ###################
PrintMatrix:
   la $t2,array  
   lw $s0,rowSize
   lw $s1,colSize
   li $t0,0       # i=0
L1:
   li $t1,0       # j=0
L2:
   mul $t3,$t0,$s0
   add $t3,$t3,$t1
   mul $t3,$t3,4
   add $t3,$t3,$t2
   lw $a0,($t3)  
   li $v0,1
   syscall           # print A(i,j)
   la $a0,space
   li $v0,4
   syscall
  
   add $t1,$t1,1       # j=j+1
   bge $t1,$s1,exitL2   # if i>colSize, go to exitL2
   j L2
exitL2:
   la $a0,newLine       # print new line
   li $v0,4
   syscall
   add $t0,$t0,1       # i=i+1
   bge $t0,$s0,exitL1   # if i>rowSize, go to exitL1
   j L1
exitL1:
   jr $ra           # return to main
################# TransposeMatrix ###################
TransposeMatrix:
   la $t2,array  
   lw $s0,rowSize
   lw $s1,colSize
   li $t0,0       # i=0
   li $t1,0       # j=0
loopL1:  
loopL2:
   mul $t3,$t0,$s0
   add $t3,$t3,$t1
   mul $t3,$t3,4
   add $t3,$t3,$t2
   lw $t4,($t3)       # $t4=A(i,j)

   mul $t5,$t1,$s0
   add $t5,$t5,$t0
   mul $t5,$t5,4
   add $t5,$t5,$t2
   lw $t6,($t5)       # $t6=A(j,i)
  
   # swap A(i,j) and A(j,i)
   move $s2,$t4
   sw $t6,($t3)
   sw $s2,($t5)  
  
   add $t1,$t1,1       # j=j+1
   bge $t1,$s1,exitLoopL2   # if i>colSize, got to exitLoopL2
   j loopL2
exitLoopL2:
   la $a0,newLine
   li $v0,4
   syscall
   add $t0,$t0,1       # i=i+1
   bge $t0,$s0,exitLoopL1   # if i>rowSize, got to exitLoopL1
  
   move $t1,$t0       # i=j
   j loopL1
exitLoopL1:
   jr $ra           # return to main


Related Solutions

This is to be done with MIPS assembly language. Write MIPS code which is equivalent to...
This is to be done with MIPS assembly language. Write MIPS code which is equivalent to the follow java program: int day = (int)(Math.random() * 7); switch (day) { case 1: System.out.println(“Monday”); break case 2: System.out.println(“Tuesday”); break case 3: System.out.println(“Wednesday”); break case 4: System.out.println(“Thursday”); break case 5: System.out.println(“Friday”); break case 6: System.out.println(“Saturday”); break case 0: System.out.println(“Sunday”); break }
need a code MIPS assembly language program to implement algorithms of an 8-bit integer "positive integer"...
need a code MIPS assembly language program to implement algorithms of an 8-bit integer "positive integer" to calculate the square root for an-8 bit integer using The Radix-2 SRT-Redundant and Non-Redundant Algorithm to approximate square root
Write a mips assembly code program that ask the user to enter an integer value, and...
Write a mips assembly code program that ask the user to enter an integer value, and then print the result of doubling that number.
Write a MIPS assembly language program to read an arbitrary number of integer pairs from a...
Write a MIPS assembly language program to read an arbitrary number of integer pairs from a file. Each pair will then be multiplied together with the results being accumulated (added together) forming a sum-of-products operation. Submit your report and code here.
Write a MIPS assembly language program that implements the following pseudo-code operation: result = x +...
Write a MIPS assembly language program that implements the following pseudo-code operation: result = x + y – z + A[j] x and y should be in reserved memory words using the .word directive and labeled as x and y. Initialize x=10 and y=200. Read in z from the console. Input the value -8. This is the value for z, not for –z. Store this value in memory with the label z. To begin, you could just initialize z to...
A square matrix A is said to be symmetric if its transpose AT satisfies AT= A,...
A square matrix A is said to be symmetric if its transpose AT satisfies AT= A, and a complex-valued square matrix A is said to be Hermitian if its conjugate transpose AH = (A)T = AT satisfies AH = A. Thus, a real-valued square matrix A is symmetric if and only if it is Hermitian. Which of the following is a vector space? (a) The set of all n xn real-valued symmetric matrices over R. (b) The set of all...
Use MIPS assembly language program to swap two of the integers in an integer array. The...
Use MIPS assembly language program to swap two of the integers in an integer array. The program should include the Swap function to swap the integers and the main function to call the Swap function. The main function should: • Pass the starting address of the array in $a0. • Pass the indices of the two elements to swap in $a1 and $a2. • Preserve (i.e. push onto the stack) any T registers that it uses. • Call the Swap...
I'm trying to code in MIPS (MIPS Assembly Language) to calculate the hamming distance between two...
I'm trying to code in MIPS (MIPS Assembly Language) to calculate the hamming distance between two integers. Ideally, the program would ask for the user to type in the two integers. Then, the program would calculate the hamming distance. Afterward, it would ask if you'd like to find another hamming distance. If the user says yes, it would loop back to the beginning and ask for two new integers. Below is the code that I've created so far. Guidance with...
Write the code in assembly language to generate two square waves of frequency 1KHZ with 50%...
Write the code in assembly language to generate two square waves of frequency 1KHZ with 50% duty cycle and 10KHZ with 50% duty cycle using P1.0 and P1.1 using timer0 and timer1 simultaneously. Don't use instruction overhead. use timer interrupts to implement the functionality use Xtal=12MHZ
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user toinput an...
MIPS Assembly LanguageWrite a MIPS assembly language program that asks the user to input an integer and then prints out a string that shows how that integer should be encoded using 16 bits. Your program should handle both positive and negative valued inputs. Your program should also print out an error message if the given input cannot be expressed as a 16 bit signed integer.As an example, if the input is 12, your program should output “0000000000001100”. If the input...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT