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,开发者_JAVA技巧 $v0 , $t1 # set $t1 = 4 * n
I'm using the SPIM simulator.
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.
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.
精彩评论