# Matrix .data # Data declaration section Matrix1: .space 100 Matrix2: .space 100 size: .asciiz "size:" promptInt1: .asciiz "\n Element of first matrix: " promptInt2: .asciiz "\n Element of second matrix: " .text main: # Start of code section addi $s0,$zero,25 addi $t0,$zero,0 loop1: li $v0,4 la $a0,promptInt1 syscall li $v0,5 syscall add $t1,$t0,$zero sll $t1,$t0,2 add $t3,$v0,$zero sw $t3,Matrix1 ( $t1 ) addi $t0,$t0,1 slt $t1,$s0,$t0 #if (s0<t0) t1=1 beqz $t1,loop1 #if(t1=1) goto loop1 la $a0,Matrix1 addi $a1,$s0,1 show1: lw $a0,0($t1) li $v0,1 syscall addi $t0,$t0,4 addi $t1,$t1,1 li $v0,4 syscall slt $t2,$s0,$t1 beqz $t2,show1 #ending li $v0,10 syscall # END OF PROGRAM
MIPS Matrices multiplyingHow to declare second matrix
Page 1 of 1
1 Replies - 3777 Views - Last Post: 25 May 2010 - 11:57 AM
#1
MIPS Matrices multiplying
Posted 25 May 2010 - 08:14 AM
Hi, I have question: How to define a second matrix in this code. I have to multiply matrices eg. 5x5 or 4x4 etc. I am a beginner in MIPS and I have no idea how to do it. Thanks for helping.
Replies To: MIPS Matrices multiplying
#2
Re: MIPS Matrices multiplying
Posted 25 May 2010 - 11:57 AM
Think of matrices as an array of floats. Real Mode 32-bit single-precision floating-point values are 4x4 x4 bytes each so an array of 64 bytes.
Before jumping into it in assembly you should work it out in a higher level language!
There are many flavors of MIPS processors. Most don't have packed floating-point, some do. Here's a code snippet for a dot product as possibly a place for you to start!
One method of vector declaration.
Before jumping into it in assembly you should work it out in a higher level language!
C = A x B C00 = A00 x B00 + A10 x B01 + A20 x B02 + A30 x B03 etc.
There are many flavors of MIPS processors. Most don't have packed floating-point, some do. Here's a code snippet for a dot product as possibly a place for you to start!
// Dot Product (MIPS V & MIPS-3D)
//
// void vmp_DotProduct(float * const pfD, const vmp3DVector * const pvA, const vmp3DVector * const pvB)
//
.align 3
.global vmp_DotProductMIPS3D
vmp_DotProductMIPS3D:
ASSERT_PTR16(a1)
ASSERT_PTR16(a2)
ASSERT_PTR4(a0)
ldc1 $f4, 0(a1) // {Ay Ax} Mem to PS_FP
ldc1 $f6, 0(a2) // {By Bx}
lwc1 $f5, 8(a1) // { Az}
lwc1 $f7, 8(a2) // { Bz}
mul.ps $f4, $f4, $f6 // {AyBy AxBx}
mul.s $f5, $f5, $f7 // { AzBz}
addr.ps $f4, $f4, $f4 // {AyBy+AxBx AyBy+AxBx}
add.s $f5, $f5, $f4 // { AzBz+AyBy+AxBx}
swc1 $f5, 0(a0)
j ra // ret
BDELAY // nop = Branch Delay Slot
One method of vector declaration.
.dword 0xffff0000ffff0000,0xffff0000ffff0000
This post has been edited by wildgoose: 25 May 2010 - 12:17 PM
Page 1 of 1
|
|

New Topic/Question
Reply




MultiQuote




|