MIPS assembly programming - converting integer to decimal/binary

Click For Summary
A MIPS assembly program is being developed to display an integer in either decimal or binary format using a single function that accepts two parameters: the integer and the base (2 for binary, 10 for decimal). The key approach involves repeatedly dividing the integer by the specified base and storing the remainders, which represent the digits in reverse order. It is important to implement additional logic to correctly handle negative integers, ensuring they are represented accurately in both formats. The focus is on creating a function that adheres to these requirements without modifying other parts of the program.
colerelm
Messages
2
Reaction score
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
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:
Learn If you want to write code for Python Machine learning, AI Statistics/data analysis Scientific research Web application servers Some microcontrollers JavaScript/Node JS/TypeScript Web sites Web application servers C# Games (Unity) Consumer applications (Windows) Business applications C++ Games (Unreal Engine) Operating systems, device drivers Microcontrollers/embedded systems Consumer applications (Linux) Some more tips: Do not learn C++ (or any other dialect of C) as a...

Similar threads

  • · Replies 102 ·
4
Replies
102
Views
2K
  • · Replies 25 ·
Replies
25
Views
722
Replies
16
Views
4K
  • · Replies 3 ·
Replies
3
Views
11K
  • · Replies 4 ·
Replies
4
Views
5K
  • · Replies 16 ·
Replies
16
Views
2K
  • · Replies 20 ·
Replies
20
Views
6K
Replies
6
Views
3K
  • · Replies 4 ·
Replies
4
Views
7K
Replies
9
Views
30K