Category:MIPS Assembly: Difference between revisions

m
m (rearranged some chapters for better flow)
 
(8 intermediate revisions by the same user not shown)
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==
* [[wp:MIPS_architecture|MIPS architecture]]
* [https://en.m.wikibooks.org/wiki/N64_Programming/CPU_overview Overview of N64 Architecture]
* [https://www.chibialiens.com/mips/ A multiplatform tutorial of MIPS Assembly programming with examples and downloadable dev tools]
1,489

edits