MIPS Matrices multiplying

How to declare second matrix

Page 1 of 1

1 Replies - 14254 Views - Last Post: 25 May 2010 - 11:57 AM Rate Topic: -----

#1 szacik   User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • 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: "


main:		# Start of code section
	addi $s0,$zero,25
	addi $t0,$zero,0
	li $v0,4
	la $a0,promptInt1
	li $v0,5
	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
	lw $a0,0($t1)
	li $v0,1
	addi $t0,$t0,4
	addi $t1,$t1,1
	li $v0,4
	slt $t2,$s0,$t1		 
	beqz $t2,show1

	li $v0,10

Is This A Good Question/Topic? 0
  • +

Replies To: MIPS Matrices multiplying

#2 wildgoose   User is offline

  • D.I.C Regular
  • member icon

Reputation: 67
  • View blog
  • 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

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


    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

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1