The part of the code in question is attempting to decode what register is being used by a MIPS instruction.
This does it by passing in an integer value of the register and then should return a string containing the name of the register. The prince statement that does it is here, where it calls getReg to get the string.
printf("$%d aka $%s\n", itype->rs, getReg(itype->rs));
So far, I've tried this to concatenate them (without the case statements):
char* getReg(int d) {
char out[4];
sprintf(out, "a%d", (d - 4));
return out;
}
But the output results in this:
$6 aka $ìü(
When it should be:
$6 aka $a2
Where am I going wrong with this?
outis large enough is irrelevant, returning a local array is still undefined behavior.printfafter yoursprintfand see. Also, use the GDB, helps a lot