Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Here you go, a simple version that translates your C code into MIPS:</p> <p>Note: I am using SPIM for this.</p> <pre><code>main: li $t0, 2 # $t0 = x = 2 li $t1, 0 # $t1 = index = 0 li $t2, 4 # $t2 = indexLimit = 4 jal forLoop # jump and link the forLoop label move $a0, $t0 # move the result into $a0 for printing li $v0, 1 # load print integer code syscall # tell system to do it li $v0, 10 # load exit code syscall # clean exit forLoop: bge $t1, $t2, exit # if index &gt;= 4 goto exit label add $t0, $t0, $t1 # x = x + index addi $t1, $t1, 1 # index++ j forLoop # continue loop by jumping back up exit: jr $ra # jump and return the return address </code></pre> <p>To answer your question: <code>nop</code> does nothing at all. You can use it for timing purposes etc. Here is a Wikipedia link for further reading <a href="http://en.wikipedia.org/wiki/NOP" rel="nofollow">http://en.wikipedia.org/wiki/NOP</a>. Note to end a MIPS program load 10 into $v0 and then syscall.</p> <p>EDIT:</p> <p>In response to your comment: you are on the right track but don't forget to add a main label, then jump from the main label to the forLoop and then have your Exit label terminate the program (print the integer first if so desired).</p> <p>These are two useful links for programming in MIPS: <a href="http://www.mrc.uidaho.edu/mrc/people/jff/digital/MIPSir.html" rel="nofollow">http://www.mrc.uidaho.edu/mrc/people/jff/digital/MIPSir.html</a> <a href="http://logos.cs.uic.edu/366/notes/mips%20quick%20tutorial.htm" rel="nofollow">http://logos.cs.uic.edu/366/notes/mips%20quick%20tutorial.htm</a></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload