1

I have currently implemented a mips programme which reads in four Base64 characters into registers $s0, $s1, $s2, $s3. I understand that decoding into base 64 characters is taking 6 bit characters and re grouping them into 8 bits. I found this Java code online that writes the decoding process like this:

for (i = numberQuadruple - 1; i > 0; i--) {
      decodedData[encodedIndex++] = (byte) (b1 << 2 | b2 >> 4);
      decodedData[encodedIndex++] = (byte) (((b2 & 0xf) << 4) | ((b3 >> 2) & 0xf));
      decodedData[encodedIndex++] = (byte) (b3 << 6 | b4);}

and I know the OR operator is to put two chars together and the shift left and shift right operators is to shift the bits in place but I'm not sure how exactly it does that and how to implement this in assembly?

Sook Lim
  • 541
  • 6
  • 28
  • If your four base64 characters start at a word-aligned address, you can just load the word and shift / mask it, I think. Although those `b` values look like they've already been translated from ASCII into a 6-bit integer according to the Base64 6-bit integer <-> ASCII character code table https://en.wikipedia.org/wiki/Base64#Base64_table. So you wouldn't have that in memory. – Peter Cordes May 07 '19 at 10:33
  • Unfortunately Base64 doesn't use a single sequential range of ASCII codes, so need to branch or use a lookup table instead of just subtracting a constant from the ASCII code. BTW, https://tools.ietf.org/html/rfc3548.html describes in English the details of dividing bits between output characters when encoding (and thus implies how to decode it, by doing the reverse.) – Peter Cordes May 07 '19 at 10:44

0 Answers0