Department of Electrical and Computer Engineering
Rutgers, The State University of New Jersey
Computer Architecture and Assembly Lab
Fall 2021
Lab 5
RISC-V Functions and Pointers
100 Points Total
Instructions
Please answer all the questions below. You need to use the Venus RISC-V simulator for running and
testing your code. Note that the simulator is 32-bit, and we do not consider overflow here.
Upload your lab report with the department cover page and your source code using Sakai.
Comment your code for clarity!
Exercises
1. [30 pts] Write a RISC-V program in Venus simulator that accepts an input integer 𝑥 and performs
the following functions:
• Recursive function: 𝑓(𝑥) = 𝑓(𝑥 − 1) + 2 ∗ 𝑥
• Iterative/loop function: 𝑓(𝑥) = 2 ∗ 𝑥 + 2 ∗ (𝑥 − 1) + 2 ∗ (𝑥 − 2) + ⋯ + 2 ∗ 2 + 2 ∗ 1
The base case for recursion is 𝑓(0) = 0. You can assume 𝑥 is always greater than 0.
In the program, please have a main function that takes the value of the input, perform the computations
by the two functions with the same input value, and print the outputs of the two methods in the console.
• Verify your program for 3 different input values 𝑥1, 𝑥2, and 𝑥3 such that 𝑥1 ≠ 𝑥2 ≠ 𝑥3.
Note: you need to provide your own inputs and show screenshots of the outputs based on the given
inputs. (Each method worth 12 pts, each demonstration worth 2 pts.)
2. [30 pts] Write a RISC-V program in Venus simulator that splits the given array {-5, 2, -11, -6, 0, 8}
to be the following new arrays:
• Array 1: the elements are the odd negative numbers, stored starting at address 0x11001100
• Array 2: the elements are the even positive numbers, stored starting at address 0x33003300
• Array 3: the elements are all zeros, stored starting at address 0x7fff0000
In the program, please have a main function that obtain the value of the input, split the array, and print
the three arrays in the console. Your implementation should work for arrays of different values as well.
Note: you need to show screenshots of the outputs based on the given input. (Each array worth 10 pts.)
https://kvakil.github.io/venus/
Department of Electrical and Computer Engineering
Rutgers, The State University of New Jersey
3. [40 pts] Write a RISC-V program in Venus simulator that checks if the input matrix is a symmetric
matrix. Specifically, you need to check if the matrix M is a square matrix and the matrix is equal to its
transpose MT. The transpose of the matrix M means the i-th row, j-th column element of MT is the j-th
row, i-th column element of M.
In the program, please have a main function that calls the symmetric function and print 1 or 0 (1 means
it is symmetric and 0 means it is not symmetric) in the console. [25 pts]
• Verify your program for 3 input matrices 𝑚1, 𝑚2, and 𝑚3 such that the dimensions of 𝑚1, 𝑚2,
and 𝑚3 are all unique. [3 pts each]
• Demonstrate each possible case (i.e. symmetric, not symmetric, not square) at least once. If the
matrix is not square, your implementation should return the error code 303. Hint: please refer to
the Ecall wiki page about returning the error code
(https://github.com/kvakil/venus/wiki/Environmental-Calls). [2 pts each].
Note: you need to provide your own inputs and show screenshots of the outputs based on the given
inputs.
https://github.com/kvakil/venus/wiki/Environmental-Calls