Conditional structures: Difference between revisions
Content added Content deleted
m (→{{header|Phix}}: added js tag) |
Puppydrum64 (talk | contribs) |
||
Line 4,295: | Line 4,295: | ||
{{out}} |
{{out}} |
||
<pre>checking smallness</pre> |
<pre>checking smallness</pre> |
||
=={{header|MIPS Assembly}}== |
|||
MIPS is a bit unusual in that it doesn't have "flags" per se. Every branch instruction takes one or more registers as an operand and does the comparison there. |
|||
<lang mips>BEQ $t0,$t1,Label ;branch to label if $t0 = $t1. If not, fallthrough to the instruction after the delay slot. |
|||
nop ;branch delay slot</lang> |
|||
If you're wondering how the delay slot impacts the comparison, it doesn't. The delay slot instruction executes after the comparison has been made and CPU has decided whether to branch. (See [[MIPS Assembly]] for more info on what delay slots are.) As a result, code like this can introduce subtle off-by-one errors: |
|||
<lang mips>BNEZ $t0,loop ;branch if $t0 is nonzero. |
|||
subiu $t0,1 ;this finishes at the same time the jumpback occurs.</lang> |
|||
MIPS also comes with greater than/less than constructs built-in. |
|||
* <code>BLT</code> <tt><</tt> |
|||
* <code>BLE</code> <tt><=</tt> |
|||
* <code>BGT</code> <tt>></tt> |
|||
* <code>BGE</code> <tt>>=</tt> |
|||
Adding a <code>U</code> to the end of any of the above makes the comparison unsigned. Remember, in assembly ''there are no signed/unsigned numbers, only signed/unsigned comparisons!'' |
|||
<lang mips>BGEU $t0,$t1,label ;branch if $t0 >= $t1, treating both as unsigned. |
|||
NOP |
|||
BLT $t7,$t3,label ;branch if $t7 < $t3, treating both as signed |
|||
NOP</lang> |
|||
=={{header|МК-61/52}}== |
=={{header|МК-61/52}}== |