106 - Exercises

Below are a number of programming exercises. The aim is that you 1) prepare a working setup, and 2) that you refresh you low-level C programming skills. In the exercises where inputs are required, these inputs can be hardcoded as we have no means of inputting data to the processor.

Exercise 101

For this exercise you should simply try to get the examples of this chapter to work.
  1. create a Vivado project
  2. import the picorv32.v description
  3. import the testbench and the memory model
  4. generate the .hex file
  5. run the simulation
  6. parse the output
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

For this exercise you will re-organise the memory map. In stead of writing all output to 0x10000000 to the file, update the design so it writes all output to 0x80000000 to the file.

Exercise 103

Write a firmware function get_hamming_weight() that can calculate 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 can calculate 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 get_factorial() that calculates the factorial of an unsigned integer. Print the result to the output.
unsigned int get_factorial(unsigned int x);

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. Print the result to the output.
unsigned int convert(unsigned int x);

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

(0F − 32) × 59 = -17,78 °C