ISA & Assembly

What does the RISC-V instruction "jal ra, func" do?

  1. ASaves the address of the next instruction in ra, then jumps to func
  2. BOnly puts the address of func in ra and does not jump
  3. CReturns to the address held in ra
Show answer and explanation

Answer: A. Saves the address of the next instruction in ra, then jumps to func

jal (jump and link) writes the address of the next instruction (PC + 4) into the given register (the link) and jumps to the target. The calling convention puts the return address in ra (x1), so a call is written "jal ra, func", or "call func" as a pseudo-instruction. The called function returns to the address in ra when it finishes. With x0 as the destination, jal becomes a plain jump.

  • A. Correct. This is the call instruction.
  • B. jal also jumps.
  • C. Returning is done by ret (jalr).
Practice this topic Back to topic

More ISA & Assembly questions

  1. Which real instruction executes the RISC-V pseudo-instruction "ret"?
  2. What is the main purpose of defining a calling convention?
  3. In the standard RISC-V calling convention, which registers pass integer arguments and return values?
  4. In the standard RISC-V calling convention, when calling a function with ten integer arguments, where are the ninth and tenth passed?
  5. In the RISC-V calling convention, s0-s11 are callee-saved registers. What does that mean?