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.

An example of the file structure can be seen here.

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

Complete the print_dec() function.

Exercise 103

Update the simulation so that the output address is 0x8000000.

Exercise 104

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 105

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 106

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 107

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

Print the result to the output.

unsigned int convert(unsigned int x);

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

( F − 32) × 5/9 =  °C
e.g. 32 F = 0 °C
     86 F = 30 °C


Handing in exercises

When you upload your assigments, check the following:

          • all your files are archived in one single file (.zip, .tar, …)
          • structurise your files in subfolders
              • firmware/ containing all the software: build files, binaries, …
                  • firmware/src/ containing all the source files (.c, .S, …)
              • hdl/ containing all the hardware descriptions (.vhd, .v, .sv, …)
                  • hdl/tb/ containing all the simulation files (.vhd)
              • files like a README.md, vivado_script.tcl, …
                  • README.md: if you want to add some additional info
                  • vivado.tcl: script to automate project creation in Vivado

Tree

If you look at the structure of how you need to hand in assignments, you might spot something. These are all plain text files and there are not many of them. However, this will enable you to generate all data you need: binaries, hex-files, vivado projects, bitstreams, …
In case you want to use some version control (like GitHub), it would make sense to track only these files.