LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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
 
Search this Thread
Old 10-02-2005, 04:16 PM   #1
kponenation
Member
 
Registered: Jul 2004
Location: New Orleans, Louisiana
Distribution: Slackware 10.1
Posts: 142

Rep: Reputation: 15
MIPS question...


3x3 matrix multiplier I wrote in C

Code:
void multiply_matrices(int [3][3], int [3][3], int [3][3]);


void show_resulting_matrix(int a[][3]);


int main(void)
{

   int a[3][3] = {  {5, 9, -7}, {6, 1, 3}, {-5, 2, 5}  };

   int b[3][3] = {  {2, 9, 0}, {7, 0, 2}, {1, 1, 6}  };

   int c[3][3];


   multiply_matrices(a, b, c);

   
show_resulting_matrix(c);

}



void multiply_matrices(int a[3][3], int b[3][3], int c[3][3])
{

   int i=0;

   
   while(i < 3)

   {
   
   int j=0;

   
	 while(j < 3)

	 {
	 
	int k=0;

	int temp = 0;
	
	
	    while(k < 3)

	    {    
		 temp = a[i][k] * b[k][j] + temp;

		 c[i][j] = temp;

		 k++;

	    }
	    j++;

	 }
	 i++;

   }

}


void show_resulting_matrix(int a[3][3])

{
   int i=0;

   
   while (i < 3)

   {
   
   int j=0;

   
	 while (j < 3)

	 {
	    printf("%d\t", a[i][j]);

	    j++;

	 }

	 
	 printf("\n");

	 i++;

   }


}// end of matrix.c
I need to translate this into MIPS instructions.
But I dont' know how to start. Can anyone show me how to use multiple array(i.e. a[3][3]) and index to call the stored values?
Thank you.

Last edited by kponenation; 10-02-2005 at 04:18 PM.
 
Old 10-03-2005, 09:14 AM   #2
nixcraft
Member
 
Registered: Nov 2004
Location: BIOS
Distribution: RHEL3.0, FreeBSD 5.x, Debian 3.x, Soaris x86 v10
Posts: 379

Rep: Reputation: 30
Sorry but i'm not getting you. What do you mean by MIPS? If you mean MIPS baed Linux ( mips-based platforms) then you need LinuxMIPS kernel and development stuff. See url www.linux-mips.org/
 
Old 10-03-2005, 09:50 AM   #3
kponenation
Member
 
Registered: Jul 2004
Location: New Orleans, Louisiana
Distribution: Slackware 10.1
Posts: 142

Original Poster
Rep: Reputation: 15
I mean MIPS assembly language.
Thanks.
 
Old 10-03-2005, 10:53 AM   #4
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 3,849

Rep: Reputation: 592Reputation: 592Reputation: 592Reputation: 592Reputation: 592Reputation: 592
yay, my 100th post.
 
Old 10-03-2005, 10:56 AM   #5
schneidz
Senior Member
 
Registered: May 2005
Location: boston, usa
Distribution: fc-15/ fc-20-live-usb/ aix
Posts: 3,849

Rep: Reputation: 592Reputation: 592Reputation: 592Reputation: 592Reputation: 592Reputation: 592
i haven't dealt with mips before. i vaguely remember 65c02/ moto68k (from my college days).

what i would do is run cc/ gcc using the -S option. it should give you an assembly file for the platform you compiled on.

hth
 
Old 10-03-2005, 11:06 AM   #6
kponenation
Member
 
Registered: Jul 2004
Location: New Orleans, Louisiana
Distribution: Slackware 10.1
Posts: 142

Original Poster
Rep: Reputation: 15
yeah I tried that already. Since i don't have a MIPS machine, I get something similar to MASM, which is different from MIPS.
 
Old 10-03-2005, 11:28 AM   #7
rstewart
Member
 
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205

Rep: Reputation: 38
Quote:
yeah I tried that already. Since i don't have a MIPS machine, I get something similar to MASM, which is different from MIPS.
Was your compiler a native compiler, or a MIPS cross compiler? I have used GCC on a Sun Sparc running Solaris that I built to be a MIPS cross-compiler. It built perfectly acceptable MIPS object modules and executables. I also used the -S option a few times during the testing of the cross-compiler to insure that it generated the same of sort MIPS assembler that a native MIPS GCC compiler generated.
 
Old 10-03-2005, 11:38 AM   #8
kponenation
Member
 
Registered: Jul 2004
Location: New Orleans, Louisiana
Distribution: Slackware 10.1
Posts: 142

Original Poster
Rep: Reputation: 15
A native compiler. Where do I download a MIPS cross compiler?
I tried to reconfigure gcc so that it will compile to MIPS, but it didn't work.
 
Old 10-03-2005, 12:05 PM   #9
rstewart
Member
 
Registered: Feb 2005
Location: Sunnyvale, CA
Distribution: Ubuntu
Posts: 205

Rep: Reputation: 38
Quote:
A native compiler. Where do I download a MIPS cross compiler?
I don't know where to get a prebuilt cross compiler. I built the one that I used using normal gcc sources. It took a little tinkering to get it to compile properly on the Solaris system, but once that was taken care of, it worked fine.

I would presume that the latest gcc compiler would work. If it dosen't, then give the folks maintaining it an e-mail asking for help. They are very supportive.
 
Old 10-03-2005, 12:17 PM   #10
nixcraft
Member
 
Registered: Nov 2004
Location: BIOS
Distribution: RHEL3.0, FreeBSD 5.x, Debian 3.x, Soaris x86 v10
Posts: 379

Rep: Reputation: 30
According to gnu/gcc site "Cross-compilers for the MIPS as target using the MIPS assembler currently do not work, because the auxiliary programs mips-tdump.c and mips-tfile.c can't be compiled on anything but a MIPS. It does work to cross compile for a MIPS if you use the GNU assembler and linker"

I have downloaded it from MIPS tech web site http://www.mips.com/content/Products...e/content_html

I'm also hacking DLINK based router and got cross gcc tar ball from http://mcmcc.bat.ru/dlinkt/ to put my own stuff (like ssh, ftp client and other stuff) inside it .

Hope this helps.
 
Old 10-04-2005, 01:21 AM   #11
kees-jan
Member
 
Registered: Sep 2004
Distribution: Debian, Ubuntu, BeatrIX, OpenWRT
Posts: 273

Rep: Reputation: 30
Although the aside on generating mips assembly using a cross compiler is interesting, this sounds like a homework question. I recommend reading a book on mips assembly. After that it shouldn't be too hard :-)

Groetjes,

Kees-Jan
 
  


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


Similar Threads
Thread Thread Starter Forum Replies Last Post
translate C to MIPS kponenation Programming 1 10-01-2005 09:12 PM
compiler ASM for mips 32 j.vilon Linux - Software 6 09-28-2005 08:12 PM
Bluetooth on MIPS-System tomcat22 Linux - General 0 10-07-2004 05:24 AM
MIPS assembly question Gnute Programming 1 08-24-2004 05:33 PM
MIPS assembly fenriswolf Programming 0 10-17-2001 03:01 PM


All times are GMT -5. The time now is 12:41 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 Google+: linuxquestions
Open Source Consulting | Domain Registration