0

I'm doing my homework and trying to implement ROT47 cipher, i wrote pseudocode and stopped at one thing. Given the following line of pseudocode:

if (32 < code < 80) char = ascii_char(code + 47)
if (79 < code < 127) char = ascii_char(code - 47)

How could it be translated in MIPS? I can imagine how it could be with blt and bgt, but the question here is it possible to make this only with one pseudoinstruction?

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
  • 1
    You can do with one branch if you rewrite as `code - 33 < 47` and use unsigned comparison. – Jester Jan 10 '19 at 17:08
  • Also obviously you don't need to use pseudoinstructions at all so it can be done with 0 or 1 too :) – Jester Jan 10 '19 at 17:16
  • I don’t know if this helps, but equivalent pseudocode is: char = ascii_char(33 + ((code + 14) mod 94)) – prl Jan 12 '19 at 09:22
  • Semi-related: [Testing if a value is within one of two ranges](https://stackoverflow.com/a/66893955) – Peter Cordes Apr 02 '21 at 22:57

0 Answers0