Jump to content

  • Log In with Google      Sign In   
  • Create Account


Mips itoa


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 MipsHelp   Members   -  Reputation: 101

Like
0Likes
Like

Posted 05 November 2012 - 07:28 PM

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

Sponsor:

#2 Álvaro   Crossbones+   -  Reputation: 10630

Like
1Likes
Like

Posted 05 November 2012 - 08:41 PM

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[i] = "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"[x%radix];
    ++i;
    x /= radix;
  } while (x);
  std::reverse(s, s+i);
  s[i] = '\0';
}

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



#3 MipsHelp   Members   -  Reputation: 101

Like
0Likes
Like

Posted 05 November 2012 - 09:21 PM

thanks, but hope someone out there can help me with this mips code

#4 Álvaro   Crossbones+   -  Reputation: 10630

Like
0Likes
Like

Posted 06 November 2012 - 04:09 AM

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".




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS