ISA & Assembly

What is the property of register x0 (zero) in RISC-V?

  1. AIt always reads as 0, and writes to it have no effect
  2. BIt holds the return address of a function
  3. CIt acts as a flag showing whether the last result was zero
Show answer and explanation

Answer: A. It always reads as 0, and writes to it have no effect

x0 always returns 0, and writes to it are ignored. Having the constant 0 always available lets "add rd, rs, x0" copy a value, "addi rd, x0, 5" set a constant, and a destination of x0 discard a result, without extra dedicated instructions. The return address goes in x1 (ra). RISC-V has no result flags; branch instructions compare two registers directly.

  • A. Correct. It is a constant-zero register.
  • B. The return address goes in x1 (ra).
  • C. RISC-V has no flag register for results.
Practice this topic Back to topic

More ISA & Assembly questions

  1. Which describes the general-purpose integer registers of RISC-V RV32I (the 32-bit base integer instruction set)?
  2. What is the relationship between assembly language and machine code?
  3. Which real instruction does the assembler use for the RISC-V pseudo-instruction "nop" (do nothing)?
  4. What is the difference between the RISC-V "add" and "addi" instructions?
  5. After running the RISC-V code above, what is the value in register a2?