Jump Instructions

Jump instructions modify the program counter so that executation continues at a specified memory address, no matter (almost) the value of the current program counter. Branch instructions, by contrast, are always relative to the current program counter.

There are four different basic jump instructions. You can specify a register that contains the jump target address or you can specify the jump target address as an immediate operand. For either choice, you can place a return address (PC+4) in register ra (r31) for later use.

Instruction Description Function
callCall subroutine ra = PC + 4
PC = {PC[31:28],JTA,2'b00}
callr Call subroutine in register ra = PC + 4
PC = rA
jmpComputed jump
PC = rA
jmpiJump immediate PC = {PC[31:28],JTA,2'b00}
ret Return from subroutine PC = ra
nextpcget address of following instruction rC = PC + 4

Notes:

The immediate operand for the call instruction, the jump target address (JTA) defines only the low 28-bits of the address. The upper four bits are taken from the program counter.

The nextpc instruction is the only way for a program to access the program counter (PC) directly.

If you look through a disassembly listing you will see that only the call and ret instructions are found in the user-written code. There are a couple of computed jump (jmp) instructions in the system code. There are no occurances of callr.

Instruction Format for Call Instructions

Note that the destination register for the callr instruction is hard-coded in the instruction - not user specified.

Instruction Format for Jump/Return/NextPC Instructions

The destination register (ra) is hard-coded in the ret instruction, not user-specified.

It is illegal (or at least bad form) to use the jmp instruction to jump to the address contained in register r31 (ra). Use the ret instruction to return from a subroutine called by call or callr.

Note that rC, which specified the destination for PC+4 in the call instructions, is zero and we could not store any value there if we tried.

Jump/Call Similarities

The R-format instructions in this group all perform the same basic operations.

instructionAC
nextpcr0rC
callrrAr31
jmprAr0
retr31r0

The call instruction is a special case. It is a J-format not an R-format instruction and does not have register fields. This means that destination register has to be assigned separately in the Verilog hardware implementation.


Maintained by John Loomis, updated 24 September 2008