I signed up because I've been googling forever for an answer to this question and can't find one.
I'd like to know if the jump instructions WITHOUT linking are strictly necessary in MIPS?
I can imagine for example that using "AL" versions when not required would incur some power penalty, but is there any situation (that's not completely contrived or could be coded around relatively simply) where ONLY J/JR would work?
Thank you!
J
/JR
can be emulated withJAL
/JALR
as the latter performs a super-set of the operations of the former.As @Jester pointed out, routines (functions in C jargon) must be careful to preserve their return address present in
$ra
.Unless the routine is a leaf routine (one that doesn't do any call)
$ra
must be saved somewhere anyway.Actually both
JAL
/JALR
andJ
/JR
can be implemented one in terms of the other:Emulate
JAL
/JALR
withJ
/JR
Emulate
J
/JR
withJAL
/JALR
For this to work, the code must return to
epilog
. It is assumed that$ra
is mostly preserved in routines (hence the names of the labels). Many thanks to @EOF for point out a mistake in this snippet.As @Peter pointed out, the access to the
$pc
leads to an easier (for humans) emulation ofJAL
/JALR
.As @EOF pointed out, some RISC machine actually have only one instruction for
JAL
/JALR
andJ
/JR
given their innate entanglement.Considering that jumps and call happen very often in a typical program, being able to implement easily (and executing them fast) is mandatory for any successful ISA.