Category:MIPS Assembly: Difference between revisions

m
(→‎Instruction Set: having this info is kind of redundant since the user can just look at the documentation.)
Line 40:
Branch delay slots affect all versions of MIPS. This is the phenomenon where the instruction immediately after a branch is actually executed <i>before</i> the branch takes place.
<lang mips>jal PrintString
addiu $a0,1 ;thisonce instructionthe isprogram executedcounter BEFOREbecomes the calladdress toof PrintString, this instruction has already isfinished.</lang>
On a "normal" CPU with no pipeline, the instruction after a call is not executed whatsoever until after it returns.
 
This would have the same outcome as the following, except the above version is faster than this one:
Line 52 ⟶ 53:
jal bar
nop</lang>
 
Most assemblers will refuse to allow your code to compile if certain instructions are in the branch delay slot. A branch delay slot cannot contain a branch.
<lang mips>bne $t0,$t1,skip
jal DoThing ;this can't be in a branch delay slot, and therefore won't compile.
skip:</lang>
 
Placing a <tt>nop</tt> in the slot instead will fix this.
<lang mips>bne $t0,$t1,skip
nop ;branch delay slot
jal DoThing
skip:</lang>
 
==See Also==
1,489

edits