ISA & Assembly
After running the RISC-V code above, what is the value in register a2?
addi a0, zero, 5
addi a1, a0, 3
add a2, a0, a1
- A8
- B13
- C15
Show answer and explanation
Answer: B. 13
Line 1 adds 5 to zero (always 0), giving a0 = 5; line 2 adds 3 to a0, giving a1 = 8; line 3 adds a0 and a1, giving a2 = 5 + 8 = 13. RISC-V arithmetic is written "op destination, source1, source2 (or immediate)", so the first register is where the result goes. zero is an alias of x0 and is often used to build constants.
- A. 8 is the value of a1.
- B. Correct. 5 + 8 = 13.
- C. Recheck a1: it is 5 + 3 = 8.