I am trying to translate a C program into MIPS assembly code
In my C code I have a line like this:
int base;
int count;
count = base;
In MIPS, how would I store the value of base inside of count? The only instructions I see for loading and storing are lw
and sw
and their prototypes only go from a register source -> ram destination or a ram source -> register destination.
Any help would be appreciated.
EDIT I was hoping that this could be done in a single instruction, something like
move base acc
but apparently that is impossible (at least I found no example of an instruction similar to that), I opted for this:
lw $t0, base //load base into $t0
sw $t0, count //store the value of $t0 in count
If there is a one-line instruction to do this that would be better if anyone knows one.
MIPS doesn't support direct memory-to-memory moves. (Neither do most common CPUs, actually -- even x86 doesn't.) You'll need to use
lw
/sw
to move data around.Architecturally, this is because MIPS is designed to only perform a single memory access per cycle -- doing a memory-to-memory move would require two accesses (one read, one write), or stall the pipeline.
Here's how to do it in MIPS
It is not possible to do a memory to memory move in a single instruction.