Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>for example:</p> <pre><code>beq $s0,$t0,ADDTN ADDTN: # code for addition # ... # some syscalls beq $s0.$t1,SUBTN SUBTN: . . . </code></pre> <p>I have no idea what the syscalls do (I usually don't code for MIPS).</p> <p>But you check for a condition, i. e. equality of $s0 and one of $tn, and on equality you jump to the routine that suits the case. Very well, but the routine is immediately following the <code>BEQ</code> instruction, so the branch is absolutely superfluous here. And further, if the condition is <em>not</em> met, the program continues with the code directly following the <code>BEQ</code> instruction.</p> <p>The result is that the routines (add least ADDTN) are unconditionally executed. As said, I do not know what the syscalls do, but if addition works, I guess they are kinda jumps or so.</p> <p>Anyway, you must rearrange your code so that depending on the state of the tested condition another branch of your code is executed. This is a generic "template":</p> <pre><code> beq $s0, $t0, equal # this code is executed if $s0 and $t0 differ . . jmp notequal # avoid also executing the code for equal equal: # code for the case $s0 and $t0 hold the same value . . notequal: # all that follows executes with no regard of the checked condition </code></pre> <p>There are other techniques for branching several cases like yours (you seem to have to check four operations, I guess), but you should start understanding the basics first.</p> <p>[update: Well, actually it's not that different, just that the code blocks are spread wider... /update]</p> <p>Have fun...</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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