LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices

Reply
 
LinkBack Search this Thread
Old 10-12-2005, 11:32 PM   #1
kponenation
Member
 
Registered: Jul 2004
Location: New Orleans, Louisiana
Distribution: Slackware 10.1
Posts: 142

Rep: Reputation: 15
3x3 Matrix multiplier...


I wrote 3x3 matrix multiplier in MIPS instructions.
When I run my instructions on SPIM, I get "000," which is not the correct value. Why am I getting this? Can anyone help me fix this problem?

Code:
.data
A:        .word 8, 1, 4, 6, -1, -2, 3, -2, 5
B:        .word 8, 3, 10, 3, 1, 2, 10, 8, 6
C:        .space 36
A_row:        .word 3
A_col:        .word 3
B_row:        .word 3
B_col:        .word 3
.text

main:
	la $s0, A
	la $s1, B
	la $s2, C
	lw $t0, A_row
	lw $t1, A_col
	lw $t2, B_row
	lw $t3, B_col
	li $s3, -1       #i
	li $s4, -1       #j
	li $s5, -1       #k
	j LOOP1


LOOP1:	addi $s3, $s3, 1	# i++
 	bge $s3, $t0, END	
        j LOOP2
	

	


LOOP2:	addi $s4, $s4, 1	# j++
	bge $s4, $t1, LOOP1
        j LOOP3	
	
		

LOOP3: 	addi $s5, $s5, 1	# k++  
	bge $s5, $t2, Show_C			
        mul $s6, $t1, $s3	# s6 = A_col * i
        add $s6, $s6, $s5	# s6 = s6 + k
        mul $s6, $s6, 4		# s6 = s6 * 4
        add $s6, $s6, $s0	# s6 = s6 + A
        lw $t4, 0($s6)		# load s6 to t4

        mul $s7, $t3, $s5	# s7 = B_col * k
        add $s7, $s7, $s4	# s7 = s7 + j
        mul $s7, $s7, 4		# s7 = s7 * 4
        add $s7, $s7, $s1	# s7 = s7 + B
        lw $t5, 0($s7)		# load s7 to t5
 
        mul $s8, $t3, $s3	# s8 = B_col * i
        add $s8, $s8, $s4	# s8 = s8 + j
        mul $s8, $s8, 4		# s8 = s8 * 4
        add $s8, $s8, $s2	# s8 = s8 + C
        mul $t4, $t4, $t5	# t4 = t4 * t5
        add $t6, $t4, $t6	# t6 = t4 + t6
        sw  $t6, 0($s8)		# store s8 to t6     
	 
	j LOOP3
		

Show_C: li $v0, 1
	lw $s0, 0($s8)
 	syscall		
	j LOOP2
        
END:	li $v0, 10
	lw $s0, 0($s8)
	syscall
Thanks in advance...

j
 
Old 10-27-2005, 09:16 AM   #2
naf
Member
 
Registered: Oct 2005
Location: Chicago, USA
Distribution: Slackware & Fedora
Posts: 66

Rep: Reputation: 15
My understanding is that a 3x3 matrix multiplied to anohter 3x3 matrix results in a 3x3 matrix. So the result should be nine digits. I cannot find where the inner loops are reset to -1 at the beginning of each loop. Instead of: j LOOP2, how about li $s4, -1 and li $s5, -1 for j LOOP3.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Which OS is most likely running the Matrix? vdogvictor General 29 10-17-2005 10:10 AM
Mobile processor multiplier changing? kronchev Linux - Software 2 04-06-2005 03:18 PM
Matrix Linux ryancoolest Linux - Newbie 2 09-13-2004 08:28 PM
Matrix Linux ryancoolest Linux - Hardware 1 09-13-2004 04:36 AM
The Matrix eresc Linux - Hardware 4 11-28-2003 04:59 PM


All times are GMT -5. The time now is 02:44 PM.

Main Menu
 
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: @linuxquestions
Open Source Consulting | Domain Registration