Jump anywhere: Difference between revisions
Content added Content deleted
Puppydrum64 (talk | contribs) |
Puppydrum64 (talk | contribs) |
||
Line 1,959: | Line 1,959: | ||
=={{header|MIPS Assembly}}== |
=={{header|MIPS Assembly}}== |
||
<code>j</code>, <code>jr</code>, <code>jal</code>, and <code>jalr</code> are |
<code>j</code>, <code>jr</code>, <code>jal</code>, and <code>jalr</code> are able to take you to '''anywhere''' in the CPU's address space. |
||
* <code>j 0xNNNNNNNN</code> sets the program counter equal to <code>0xNNNNNNNN</code>. |
* <code>j 0xNNNNNNNN</code> sets the program counter equal to <code>0xNNNNNNNN</code>. |
||
* <code>jr $NN</code> sets the program counter equal to the value in register <code>$NN</code>. |
* <code>jr $NN</code> sets the program counter equal to the value in register <code>$NN</code>. |
||
* <code>jal 0xNNNNNNNN</code> sets the program counter equal to <code>0xNNNNNNNN</code>, and moves the old program counter plus 8 into register <code>$ra</code>. |
* <code>jal 0xNNNNNNNN</code> sets the program counter equal to <code>0xNNNNNNNN</code>, and moves the old program counter plus 8 into register <code>$ra</code>. |
||
* <code>jalr $NN,0xNNNNNNNN</code> sets the program counter equal to <code>0xNNNNNNNN</code> and moves the old program counter into register <code>$NN</code>. |
* <code>jalr $NN,0xNNNNNNNN</code> sets the program counter equal to <code>0xNNNNNNNN</code> and moves the old program counter plus 8 into register <code>$NN</code>. |
||
Branches apply a signed offset to the current program counter. They are limited only by distance; scope does not exist in assembly. Typically you do not have calculate this offset yourself. The assembler will abstract this out of the hardware and let you use a label like you would with a <code>j</code>. The actual offset is calculated during the assembly process, which means you don't have to measure it yourself by counting bytes. |
Branches apply a signed offset to the current program counter. They are limited only by distance; scope does not exist in assembly. Typically you do not have calculate this offset yourself. The assembler will abstract this out of the hardware and let you use a label like you would with a <code>j</code>. The actual offset is calculated during the assembly process, which means you don't have to measure it yourself by counting bytes. |