Exercises
A collection of exercises for practicing RISC-V assembly, from simple arithmetic to more complex programs.
How it works
Section titled “How it works”Each exercise presents an assembly program to be traced instruction by instruction. For each step:
- Look at the next instruction to be executed and write it in the table along with its PC address
- Run that instruction in the simulator
- Check which register was modified and record its new value in the corresponding column
Repeat until the program ends
Pseudo-instructions
Section titled “Pseudo-instructions”Some exercises use pseudo-instructions such as la, j, jr, and nop. In the simulator’s text segment, each instruction is shown in two columns:
- Basic: the real instruction generated by the assembler
- Source: the original pseudo-instruction as written in the source code
When a row corresponds to a pseudo-instruction, fill in both columns of the table: copy the Basic value into the Instruction column and the Source value into the Pseudo-instruction column.
After completing an exercise, use the Save as PDF button to export and keep your answers
- ➤ Exercise 1
Arithmetic operations using addi, add and sub instructions.
- ➤ Exercise 2
Array manipulation and memory addressing with lw, sw and la instructions.
- ➤ Exercise 3
Conditional branching with the beq instruction and if-statement control flow.
- ➤ Exercise 4
If-else control flow using bne and unconditional jump with the j instruction.
- ➤ Exercise 5
While loop with array indexing using lw, bne, and j instructions.
- ➤ Exercise 6
For loop control flow using slti and beq instructions.
- ➤ Exercise 7
Procedure calls using jal and jr ra instructions.
- ➤ Exercise 8
Stack usage to save and restore registers across procedure calls.