# MIPS Matrices multiplying

Page 1 of 1

## 1 Replies - 9035 Views - Last Post: 25 May 2010 - 11:57 AMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=175095&amp;s=8f41c15810ce933408997617239c6625&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 szacik

Reputation: 0
• Posts: 5
• Joined: 25-April 10

# 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.

```# 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

loop1:
li \$v0,4
la \$a0,promptInt1
syscall
li \$v0,5
syscall
sll \$t1,\$t0,2
sw \$t3,Matrix1 ( \$t1 )
slt \$t1,\$s0,\$t0		#if (s0<t0) t1=1
beqz \$t1,loop1	#if(t1=1) goto loop1

la \$a0,Matrix1

show1:
lw \$a0,0(\$t1)
li \$v0,1
syscall
li \$v0,4
syscall
slt \$t2,\$s0,\$t1
beqz \$t2,show1

#ending
li \$v0,10
syscall

# END OF PROGRAM

```

Is This A Good Question/Topic? 0

## Replies To: MIPS Matrices multiplying

### #2 wildgoose

• D.I.C Regular

Reputation: 67
• Posts: 468
• Joined: 29-June 09

## 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!
```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