0

How can I convert this code to MIPS? I don't understand how each character in an input character pointer can be converted in MIPS.

void toUpper(char *s) {
  int n = strlen(s);
  int i;
  for (i = 0; i < n; i++) {
      s[i] &= 0xdf;
      }
  }
zzzOp
  • 105
  • 1
  • 1
  • 9
  • first hint: ask your compiler what code he will produce – Tommylee2k Apr 29 '16 at 07:36
  • I'm not exactly sure what you mean.. – zzzOp Apr 29 '16 at 07:39
  • 1
    @zzzOp Assuming you have a C compiler toolchain, compile the C code and then read the generated machine code from the resulting file. Or ask the compiler to just give you the assembly, many compilers have options to do this. – unwind Apr 29 '16 at 07:41
  • compilers do a good job compiling C to ASM, esp with optimization turned on. so whenever you have no idea what to do, compile the C code with a (cross) compiler, and see what code it produces. Just in case you don't have a C-Compiler for MIPS: I searched a bit, and found this: [http://stackoverflow.com/questions/17006843/compile-c-for-mips-architecture] – Tommylee2k Apr 29 '16 at 07:53
  • Unfortunately, I don't have a C compiler toolchain. (Edit: nevermind, the link provide is great! Thanks @Tommylee2k – zzzOp Apr 29 '16 at 07:55
  • 1
    Even if you were to do this manually I don't really see what the question is. Basic knowledge of MIPS assembly language programming would be a prerequisite for a task like this. If you don't feel that you have that - find yourself a book or tutorial on the subject and start learning. If you do know MIPS assembly you would have to clarify exactly what you're having trouble with because this seems pretty straightforward (just a couple of loops with some loads/stores and an AND-operation). – Michael Apr 29 '16 at 07:55
  • I have found this SO post: [link](http://stackoverflow.com/questions/4175450/is-there-a-way-to-use-gcc-to-convert-c-to-mips) . – user3078414 Apr 29 '16 at 07:58
  • that isn't even a valid `toUpper()` function. It'll only work reliably on 7-bit ASCII alphabetical characters and will change many other characters in unexpected ways. – Alnitak Apr 29 '16 at 08:44
  • it's inefficient too - scanning the string twice! – Alnitak Apr 29 '16 at 08:50
  • May I kindly what's the point of discouraging the OP to the point of rather not asking a question without prerequisite knowledge which would render asking pointless? It's a good point that code intended to be written in assembly language should be efficient. This algorithm is ASCII-character only indeed, and the reading procedure is inefficient, but does it disqualify? Thanks. – user3078414 Apr 29 '16 at 10:02
  • no, what disqualifies is that he didn't try himself, and just threw in his C-Code, instead of at least starting to develop. SO is no coding service – Tommylee2k Apr 29 '16 at 10:11
  • @user3078414: I'm not trying to discourage people from asking good questions. But a code dump along with _"How do I translate this from language X to language Y?"_ doesn't qualify as a good question in my book. Plus, if the question could be answered with just a basic understanding of X and Y (at least based on the information the OP has provided) then I have to question the OP's research effort. – Michael Apr 29 '16 at 10:22
  • @Tommylee2k, thanks - it wasn't my faintest idea to challenge your or anyone's opinion about SO not being a coding service, because it's clear *it is not* and it shouldn't be. Yet, whenever put into position of possibly being judgmental, I prefer keeping "on the softer side", or at least asking one extra question... – user3078414 Apr 29 '16 at 10:58

0 Answers0