Destination Register

How should the instruction sw $a0, 0($sp) be encoded in our project using the assembly generator class MipsAsmGen?

Alike by the load instructions, the destination register, which is here $sp, comes after the register for memory access. Hence the answer might be

MipsAsmGen::emitInstruction(MemoryInstruction.SW, GPRegister.SP, null, 0, GPRegister.A0);

No, you should swap the two registers.

Store instructions are encoded the exact same way as load instructions, that is, the second register parameter is used for the address.
Unfortunately, this means that the parameter called dest is actually the source, which is very confusing indeed…

1 Like