MIPS assembly programming - converting integer to decimal/binary

  • #1
colerelm
2
0
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.
 
Technology news on Phys.org
  • #2
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:

Similar threads

Back
Top