MIPS assembly programming - converting integer to decimal/binary

Click For Summary
SUMMARY

The forum discussion focuses on creating a MIPS assembly function that converts an integer to either decimal or binary format based on a specified base (2 for binary, 10 for decimal). The proposed solution involves repeatedly dividing the integer by the base and storing the remainders, which represent the digits in reverse order. Additionally, the implementation must account for negative integers, requiring extra logic to handle signed numbers. This approach allows for a single function to manage both conversions efficiently.

PREREQUISITES
  • Understanding of MIPS assembly language syntax and structure
  • Knowledge of integer division and remainder operations
  • Familiarity with handling signed integers in programming
  • Experience with stack operations and array manipulation in assembly
NEXT STEPS
  • Research MIPS assembly division and modulus instructions
  • Learn about signed integer representation in MIPS
  • Explore stack management techniques in MIPS assembly
  • Study algorithms for converting numbers between bases
USEFUL FOR

This discussion is beneficial for MIPS assembly programmers, computer science students learning low-level programming, and anyone interested in number base conversions within assembly language.

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:

Similar threads

  • · Replies 102 ·
4
Replies
102
Views
4K
  • · Replies 25 ·
Replies
25
Views
1K
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
1
Views
3K