tags:

views:

74

answers:

2

Hi,

why does such a instruction as

mul   $t1, $v0 , 4 

evaluates as expected. But

mul   $t1, 4 , $v0 

results in a syntax error!

I wonder why the first one works, because mul only works with registers per default, so I expect that only a solution like this will be workin

li   $t1, 4             # set $t1 = 4
mul   $t1, $v0 , $t1      # set $t1 = 4 * n

I'm using the SPIM simulator.

A: 

Ok, I would suggest looking at the opcode output. Perhaps the multiply by 4 is being swapped for adds or perhaps sll immediate for speed purposes. The 4,reg version may not be caught via this 'optimization' and that is why it is throwing an error.

Michael Dorgan
My first answer was dead wrong, this one should be much better :)
Michael Dorgan
How does such a swapping process work and why does it not take care of the 4 if it is swapped?
Martin K.
sll reg,2 is the same as multiply by 4 without using an extra register. I'm guessing that perhaps the assembler did this for you and wanted you to double check the opcode output to be sure.
Michael Dorgan
+1  A: 

This results in a syntax error simply because MIPS only supports the pseudo-instruction mul [rs] [rt] [imm], and not mul [rs] [imm] [rt]. I'm assuming it does this for consistency because there is no real instruction in MIPS that supports an immediate value in the middle of an instruction.

Zach Langley