MIPS assembly programming - converting integer to decimal/binary

AI Thread 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:
Thread 'Is this public key encryption?'
I've tried to intuit public key encryption but never quite managed. But this seems to wrap it up in a bow. This seems to be a very elegant way of transmitting a message publicly that only the sender and receiver can decipher. Is this how PKE works? No, it cant be. In the above case, the requester knows the target's "secret" key - because they have his ID, and therefore knows his birthdate.
I tried a web search "the loss of programming ", and found an article saying that all aspects of writing, developing, and testing software programs will one day all be handled through artificial intelligence. One must wonder then, who is responsible. WHO is responsible for any problems, bugs, deficiencies, or whatever malfunctions which the programs make their users endure? Things may work wrong however the "wrong" happens. AI needs to fix the problems for the users. Any way to...
Back
Top