• Advertisement
Sign in to follow this  

Mips itoa

This topic is 1904 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I was looking at this code from this link:
http://www.gamedev.n...o-ascii-in-asm/

How can I make it support unsigned integer.
I want to convert 3210987654 to its radix, but all i get is a negative number that doesn't correspond to it.

For base 16, for that number I'm suppose to get BF63C886. but in qtspim, I get, -409c377a

much help is very appreciated

Share this post


Link to post
Share on other sites
Advertisement
I don't know MIPS assembly, but here's a straight-forward implementation in C++, which you can easily map to assembly:
#include <iostream>
#include <algorithm>

void uitoa(char *s, unsigned x, unsigned radix) {
int i=0;
do {
s = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[x%radix];
++i;
x /= radix;
} while (x);
std::reverse(s, s+i);
s = '\0';
}

int main() {
char s[20];
uitoa(s, 3210987654u, 16);
std::cout << s << '\n';
}

Share this post


Link to post
Share on other sites
If you understand the algorithm, you should be able to boil the question down to "how do I do unsigned-integer division on MIPS", which two minutes of searching the web would tell you: "divu" instead of "div".

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement