Thread: C++ to MIPS Assembly: how to approach

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    2

    C++ to MIPS Assembly: how to approach

    Hello everyone, I have been having trouble writing a program in MIPS assembly language that performs the same function as a program in C++. The program is supposed to toggle a LED light on my chipKIT Uno32 Arduino with adjustable delay. I use MPIDE as my cross compiler.

    Code:
    /*
      Blinks
      Turns on a LED (LED 5 in this case) on for half a second, then off for the same amount of time. The cycle repeats.
    
     */
    
    void setup() {                
      // the digital pin is initialized as an output
      // Pin 13 has an LED connected (LED 5)
      pinMode(43, OUTPUT);     
    }
    
    void loop() {
      digitalWrite(43, HIGH);   // set the LED on
      delay(500);              // wait for a half second
      digitalWrite(43, LOW);    // set the LED off
      delay(500);              // wait for a half second
    }
    The program that I want to write in MIPS assembly language probably has to include a function that has to do with looping turning the LED on and off with a delay just like the C++ program. Here is where I run into a lot of questions.

    Before I want to write the part to interact with the I/O, I want the function I'm writing to just take a single argument from in a0 that is the number of milliseconds before returning. What are some things I should be considering while approaching the problem? Are there any things the program should include?

  2. #2
    Registered User
    Join Date
    Nov 2012
    Posts
    2
    On an off note (I looked through the different forums and the topic descriptions but I'm not sure where to put this) I'm taking a computer systems and assembly language class with no prior experience in assembly language and little prior experience in C++ and processing from an intro to computer science class I took before. I'll be taking the next level of this class next quarter (assuming I pass this quarter) but I feel my fundamentals in assembly language are REALLY REALLY shaky and could DEFINITELY use improvement. Are there any resources I can take advantage of over winter break to help me get better that this (it seems I'm constantly playing "catch-up" in this class) or should I just consider re-taking the class next quarter? This is the first class of this nature I'm taking so I'm doing a lot worse than how I'm doing in familiar subjects (Physics/Calculus/Linear Algebra are relatively easy).
    Last edited by primoriscruor; 11-28-2012 at 03:34 PM.

  3. #3
    Internet Superhero
    Join Date
    Sep 2006
    Location
    Denmark
    Posts
    964
    I'm not familiar with MPIDE, but i can recommend MARS if you want to get better at MIPS assembly, you can run your code in a debugger-like environment, step by step with the content of memory and all registers displayed.

    As for the delay, you can use syscall with $v0 = 32 and $a0 = x, where x is the amount of milliseconds you want to sleep for.
    How I need a drink, alcoholic in nature, after the heavy lectures involving quantum mechanics.

  4. #4
    Registered User
    Join Date
    May 2009
    Posts
    4,183
    Quote Originally Posted by Neo1 View Post
    I'm not familiar with MPIDE, ...
    They meant Microchip's MPLAB IDE; Microchip has an MIPS based MCU.

    Tim S.
    "...a computer is a stupid machine with the ability to do incredibly smart things, while computer programmers are smart people with the ability to do incredibly stupid things. They are,in short, a perfect match.." Bill Bryson

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, 08:39 PM
  4. Converting C into MIPS Assembly
    By clag in forum C Programming
    Replies: 5
    Last Post: 02-13-2010, 07: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