5 - Exercises

Practice makes perfect

Below are a number of programming exercises. The aim is that you 1) retrieve your RISC-V implementation 2) prepare a working setup, and 3) refresh your low-level C programming skills.

As a reminder … a zip archive to get you started can be found here.

Exercise 101

For this exercise you should simply try to get the zip file to work on your own RISC-V.

As FPGA device, you can pick a ZYNQ XC7Z020-1CLG400C. An even better solution is to pick the PYNQ-Z2 board in case you have the board drivers installed.

Exercise 102

Add a print_dec() function.

Exercise 103

Write a firmware function get_hamming_weight() that calculates the Hamming weight of a value.

Print the Hamming weight to the output.

unsigned int get_hamming_weight(unsigned int x);

Determine how long it takes (in clock cycles) to perform the calculation !!

Exercise 104

Write a firmware function get_hamming_distance() that calculates the Hamming distance between two values.

Print the Hamming distance to the output.

unsigned int get_hamming_distance(unsigned int x, unsigned int y);

Determine how long it takes (in clock cycles) to perform the calculation !!

Exercise 105

Write a firmware function convert() that converts temperature from Fahrenheit to degrees Celsius. The result may be rounded down to approximate the conversion.. The conversion can be calulated using this equation:

(F − 32) × 5/9 =  °C

Print the result to the output.

unsigned int convert(unsigned int x);

Determine how long it takes (in clock cycles) to perform the calculation !!

Be aware that the implementation of the RISC-V is RV32I!!