Like Tree1Likes
  • 1 Post By ledow

Converting 2D array from C to MIPS assembly language (Beginner)

This is a discussion on Converting 2D array from C to MIPS assembly language (Beginner) within the C Programming forums, part of the General Programming Boards category; Hi there guys, I am trying to understand how 2D arrays are implemented in MIPS assembly. Now I tried looking ...

  1. #1
    Banned
    Join Date
    Aug 2012
    Posts
    4

    Unhappy Converting 2D array from C to MIPS assembly language (Beginner)

    Hi there guys,

    I am trying to understand how 2D arrays are implemented in MIPS assembly. Now I tried looking online for a few examples but they have no MIPS code so its hard for me to understand the logic behind implementing 2D arrays in MIPS.

    Heres a random question I picked from a source.

    Name:  question2.JPG
Views: 1701
Size:  42.8 KB

    On first glance, the question is easy to implement in C, C#, C++ and java however, when it comes to MIPS I get confused.

    If someone can give me a sample code in MIPS then I would really appreciate it.

    Cheers

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,506
    Step 1 is write this as a 'C' function (not main).

    Step 2 is compile it with "gcc -S prog.c"

    Step 3 is study prog.s

    Step 4 is read your MIPS assembler reference manual and try to match up the assembler you see with MIPS instructions.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  3. #3
    Banned
    Join Date
    Aug 2012
    Posts
    4
    I mean I dont want to convert it without understanding it. I was wondering if someone can explain me the MIPS code after conversion.

  4. #4
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,506
    Do you have MIPS code for it already?

    > I mean I dont want to convert it without understanding it.
    There is very little danger of you arriving at MIPS code which works without you understanding it.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  5. #5
    Banned
    Join Date
    Aug 2012
    Posts
    4
    No I was wondering if someone can convert it to MIPS and explain whats happening =(

  6. #6
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,506
    MIPS Assembly Language Examples

    No, we're not here to do your work for you.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.
    I support http://www.ukip.org/ as the first necessary step to a free Europe.

  7. #7
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    There are a TON of sites brought up by Google for MIPS assembly language programming:
    Google

    Including this gem:
    Programmed Introduction to MIPS Assembly Language

    What you want is not really C language help, so that's one problem. (many of us never learned, or have long since forgotten what we were taught about MIPS assembly language).

    Second problem is we try to help people with THEIR work - it's a really rare day that we actually DO code up a problem, unless it's VERY trivial or interesting, and can't be readily discussed without having a program to show what we mean. Note that this is not the case with your problem.

    Third, your "random question" is not exactly "Hello World" is it? A first program with a 2D array in MIPS a.l., it seems to me, should consist of something far simpler.

  8. #8
    Banned
    Join Date
    Aug 2012
    Posts
    4
    Quote Originally Posted by Adak View Post
    There are a TON of sites brought up by Google for MIPS assembly language programming:
    Google

    Including this gem:
    Programmed Introduction to MIPS Assembly Language

    What you want is not really C language help, so that's one problem. (many of us never learned, or have long since forgotten what we were taught about MIPS assembly language).

    Second problem is we try to help people with THEIR work - it's a really rare day that we actually DO code up a problem, unless it's VERY trivial or interesting, and can't be readily discussed without having a program to show what we mean. Note that this is not the case with your problem.

    Third, your "random question" is not exactly "Hello World" is it? A first program with a 2D array in MIPS a.l., it seems to me, should consist of something far simpler.
    Hi there, Yes I understand basic MIPS and even implementing a 1D array. But just having difficulty with 2D arrays

  9. #9
    TEIAM - problem solved
    Join Date
    Apr 2012
    Location
    Melbourne Australia
    Posts
    1,344
    Look into indexed addressing. That's how 2D arrays are usually done in assembly.

  10. #10
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    You know that this is not an ASM board, let alone a MIPS ASM board. I strongly suggest you ask your question over on an ASM board, with a far simpler example question - and please forget the name calling.

    I can't begin to tell you how often students and lazy programmers drop requests for help similar to yours, just to get someone to do their code up for them.

    Aren't all arrays (under the hood), done by using a base address + an increment on a pointer?
    Last edited by Adak; 08-06-2012 at 05:12 AM.

  11. #11
    Registered User ledow's Avatar
    Join Date
    Dec 2011
    Posts
    435
    Quote Originally Posted by bawse.c View Post
    Dont worry about it. I have a better chance figuring out on my own rather than relying on <unnecessarily offensive remark deliberately obscured so it didn't get caught by filters> in this forum.
    Isn't that EXACTLY what we were saying to you anyway? This isn't C, at all, and this is a C forum. You want to know how something would appear in MIPS assembly, but haven't tried to write it like that yourself. You're not interested in seeing working MIPS assembler as a compiler would churn out, either. You want someone on a C forum to bypass C entirely and write their own MIPS assembly directly to solve a stated problem which looks like a class exercise to me.

    I suggest you do your own homework and never darken this forum with your presence again. But, of course, you'll have some insightful and witty comeback ready to hand, no doubt.
    Salem likes this.

    - Compiler warnings are like "Bridge Out Ahead" warnings. DON'T just ignore them.
    - A compiler error is something SO stupid that the compiler genuinely can't carry on with its job. A compiler warning is the compiler saying "Well, that's bloody stupid but if you WANT to ignore me..." and carrying on.
    - The best debugging tool in the world is a bunch of printf()'s for everything important around the bits you think might be wrong.

  12. #12
    Registered User
    Join Date
    Sep 2006
    Posts
    8,868
    Quote Originally Posted by bawse.c View Post
    you obviously didnt read my question...I posted this on a C forum because its easy to implement this in C, C#, C++ etc but you can use a compiler to convert it to assembly if you didnt know. Usually people who learn these languages also know how assembly works.

    <edited>
    Well, I don't recall much about assembly, since I barely spent any time with it, but it won't matter.

    That kind of language isn't up to our board's standards, so you will soon be booted off the forum.

  13. #13
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    21,660
    Quote Originally Posted by bawse.c
    I posted this on a C forum because its easy to implement this in C, C#, C++ etc but you can use a compiler to convert it to assembly if you didnt know.
    Obviously, you can use a compiler to convert C code to assembly, since most C compilers do that as an intermediate step. However, your question is really about MIPS, not C, regardless of how easy it is to implement in C.

    If you had provided the requisite C code that you were trying to convert and posted your best attempt, then perhaps your thread would be marginally on topic, but as it is, this whole thread is off topic.

    Furthermore, your behaviour in this thread is against the forum rules. Hence, consider this an official warning.

    *thread closed*
    C + C++ Compiler: MinGW port of GCC
    Version Control System: Bazaar

    Look up a C++ Reference and learn How To Ask Questions The Smart Way

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. MIPS Assembly Bubble Sort
    By cornfeller in forum Tech Board
    Replies: 17
    Last Post: 06-16-2012, 08:09 PM
  2. Struct node - from C to MIPS assembly language.
    By Xpl0ReRChR in forum Tech Board
    Replies: 6
    Last Post: 04-20-2012, 12:14 PM
  3. convert c programm to mips assembly
    By mariakat in forum Tech Board
    Replies: 8
    Last Post: 02-14-2011, 07:39 PM
  4. Converting C into MIPS Assembly
    By clag in forum C Programming
    Replies: 5
    Last Post: 02-13-2010, 06:48 PM
  5. A question of the MIPS assembly program
    By ok_good in forum Tech Board
    Replies: 0
    Last Post: 05-03-2006, 10:13 PM

Tags for this Thread


1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21