Skip to content

Exercise 1

Run the first example of a RISC-V assembly language program.

  1. Open the RISC-V simulator.
  2. Transcribe the code below into the editor:
# Exercise 01
# C expression: f = (g + h) - (i + j)
.text
main:
addi t1, zero, 4 # g = 4
addi t2, zero, 3 # h = 3
addi t3, zero, 2 # i = 2
addi t4, zero, 1 # j = 1
add t5, t1, t2 # t5 = g + h
add t6, t3, t4 # t6 = i + j
sub t0, t5, t6 # f = t5 - t6 (result in t0)

The first instruction modified only register t1. The remaining instructions will modify other registers. Run the program step by step and fill in the table below, recording the PC value, the instruction being executed, and the value of the registers after each instruction. Only record a register’s value when it is modified.

Fill in the table below

  • Fill in the PC with the instruction address and copy the Instruction column exactly as it appears in the simulator. Only fill in fields that are modified.
  • If you need more rows, click Add row. Verification only runs when all rows are filled, if nothing appears after clicking Check, it means there are still empty rows.
Before After executing the instruction
PC Instruction x5x6x7x28x29x30x31
(t0)(t1)(t2)(t3)(t4)(t5)(t6)
0x000000000x000000000x000000000x000000000x000000000x000000000x00000000
0x00400000 addi t1 zero 4 0x000000000x000000040x000000000x000000000x000000000x000000000x00000000

Tip: in the print dialog, select A2 paper size for best results.