Mips itoa

Started by
2 comments, last by alvaro 11 years, 5 months ago
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
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';
}

thanks, but hope someone out there can help me with this mips code
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".

This topic is closed to new replies.

Advertisement