jal address
jalr
Instruction
A
specific jal
instruction
in a program
always calls the same subroutine.
For example,
here is how main
would usually
call the first subroutine:
jal sub1
But what if you wanted the same instruction to call different subroutines depending on circumstances? This is where a jump table is useful. The table contains a list of subroutine entry points. To call a subroutine, copy its address from the table into a register. Now use the following instruction:
jalr r # $ra <— PC+4 $ra <— return address # PC <— $r load the PC with the address in $r
This works just like the jal
Here is a section of main
sub1