Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MIPS assembly programming - converting integer to decimal/binary

  1. Mar 31, 2013 #1
    I'm writing a MIPS assembly program and I'm trying to figure out a way to display a given integer in either decimal or binary using only one function with two parameters. The function takes in two parameters: an integer and a base (either '2' or '10'). I'd like to not edit anything other than just this one function.

    Can anyone help me create such a function? I can't wrap my head around the logic needed to do so using assembly language.

    Thanks in advance.
     
  2. jcsd
  3. Mar 31, 2013 #2

    rcgldr

    User Avatar
    Homework Helper

    You can get the digits in reverse order by repeatedly dividing the integer or the quotient from the previous division by the base (2 or 10), and saving the remainders (into an array or push them onto the stack), which will contain the digits (in reverse order). You'll need some extra code to handle negative numbers as signed numbers.
     
    Last edited: Mar 31, 2013
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: MIPS assembly programming - converting integer to decimal/binary
  1. Assembly Programming (Replies: 2)

  2. MIPS Decimal to Hex (Replies: 3)

  3. MIPS Decimal to binary (Replies: 3)

  4. Programming in mips (Replies: 1)

Loading...