Search code examples
assemblymipsqtspim

assembly floating point code error


these are my code lines:

li  $v0, 6      # select read_float     
syscall         # run read_float
jal p4          # run println
mfc1 $f4, $v0

The compiler gives the following error:

spim: (parser) syntax error on line 132 of file /home/robertina/Scrivania/Labo Spim/mioprogetto/mioprogetto.s mfc1 $f4, $v0

does anybody know why this lines don't work properly?


Solution

  • A quick google for MIPS mfc1 quickly shows that mfc1 is move from coprocessor 1, and that both mfc1 and mtc1 (move to coproc 1) put the FP register second (regardless of whether it's the source or destination).

    mfc1    $v0, $f4        # set $v0 = $f4
    

    (Note, don't write comments like that in your asm normally. Describe why the instruction is there, not stuff you could find out from looking it up in the assembler manual unless there's something tricky or non-obvious about it. The comments in your question are good, e.g. select read_float is more meaningful than put 6 into $v0)

    It's too bad your assembler gives such an unhelpful error message that doesn't even point you in the right direction. Most assemblers are better than that.